generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Changing Value "Attacker" in NPC when Hit by Player

Previous Thread :: Next Thread 
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 05:38 PM
I am trying to change a StringValue named "Attacker" located in an NPC when the player hits the NPC with a sword.

The localscript in the sword contains this bit of code:

hit.Parent:FindFirstChild("Attacker").Value = game.Players.LocalPlayer.Name

I'm sure the problem is that I am using a localscript to change this value while I have FE on. How could I use something like a RemoteEvent to fix this?
Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
10 Apr 2017 05:43 PM
-- Script

local ChangeValue = --Event here

ChnageValue.OnServerEvent:Connect(function(value_addr, nVal)

value_addr.Value = nVal

end)

-- Locally

local ChangeValue = --Event here

ChangeValue:FireServer(Attacker, Name)


||THEBAYOU|| - Almost famous dude
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 05:55 PM
It still tells me Attacker is a nil value. =(
Report Abuse
thebayou is not online. thebayou
Joined: 21 Dec 2014
Total Posts: 628
10 Apr 2017 05:56 PM
Duh, because you have to reference it:

local Attacker = hit.Parent:FindFirstChild("Attacker").Value
local Name = game.Players.LocalPlayer.Name


||THEBAYOU|| - Almost famous dude
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 06:04 PM
Well yeah, obviously I did that:

LocalScript:

script.Parent.RemoteClick:FireServer(hit.Parent:FindFirstChild("Attacker").Value, game.Players.LocalPlayer.Name)

Script:

script.RemoteClick.OnServerEvent:connect(function(value_addr, nVal)
value_addr = nVal
end)
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 06:10 PM
Is the script that changes the value supposed to be in the Workspace maybe?
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 06:43 PM
I put a print("Value changed.") in the script that activates with the RemoteEvent, and it does print. The problem is the value didn't actually change.
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
10 Apr 2017 06:52 PM
don't send attacker.value, send just attacker


capitalist atheist
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 07:17 PM
Now it tells me Value is not a valid member of Player..

Script(in WS):

script.RemoteClick.OnServerEvent:connect(function(Attacker, player) --value_addr, nVal
Attacker.Value = player.Name
print("Value changed.")
end)

Localscript(in tool):

player = game.Players.LocalPlayer
local Attacker = hit.Parent:FindFirstChild("Attacker")

if hit.Parent:FindFirstChild("Attacker") ~= nil then
game.Workspace.ChangeAttacker.RemoteClick:FireServer(Attacker, player)
print("Successfully communicated with RemoteClick!")
end
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
10 Apr 2017 07:28 PM
because server sided remote events always fire with the player that fires it as a first argument
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 07:28 PM
Thank you all of you =) I fixed this buy switching value_addr and nVal.
Report Abuse
UnRandomizing is not online. UnRandomizing
Joined: 20 Jun 2012
Total Posts: 1490
10 Apr 2017 07:29 PM
Oh, I guess that was the reason. Thank you for telling me, I'll be sure to remember that next time I do something similar.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
10 Apr 2017 07:30 PM
so remote event server side will fire with player,...
instead of just ...
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image