Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my tool script break when I use a Remote Event?

My ServerScript In ServerScriptService

local hum = game.Players.LocalPlayer.Character.Humanoid
print(hum)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	hum.Health = hum.Health + 2
end)

Local Script Inside My Tool

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

The Romote Event Is in ReplicatedStorage

1 comment

0

define player as local player = game.Players.LocalPlayer

1 answer

✓ Accepted answer
local hum = game.Players.LocalPlayer.Character.Humanoid

Your issue is here, as there is no localplayer as this is a server script meaning it can't print, instead try this

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local hum = game.Players.player.Character.Humanoid
	    hum.Health = hum.Health + 2
	end)

for your server script and

script.Parent.Activated:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer(player)
end)

in your local.

3 comments

0

if this doesnt work, explain to me the new error.

0

don't forget to mark as answer if this helps

0

It does not seem to be working for some reason? Player is not a valid member of Players? I don't really know what I am doing wrong here :(

This discussion is preserved as it was. New answers, comments, and votes are closed.