|
| 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
|
  |
| 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 |
|
|
|
| 10 Apr 2017 05:55 PM |
| It still tells me Attacker is a nil value. =( |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 10 Apr 2017 06:10 PM |
| Is the script that changes the value supposed to be in the Workspace maybe? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 10 Apr 2017 06:52 PM |
don't send attacker.value, send just attacker
capitalist atheist |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 10 Apr 2017 07:28 PM |
| Thank you all of you =) I fixed this buy switching value_addr and nVal. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 10 Apr 2017 07:30 PM |
so remote event server side will fire with player,... instead of just ... |
|
|
| Report Abuse |
|
|