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

How can I find the humanoid on a server sided script, after firing an event from a local script?

As the title states: I am trying to find out how can I find the player's humanoid on a server sided script?

I want to change the WalkSpeed and the JumpPower of the player that fired the event.

My script:

game.ReplicatedStorage.DialogEnd.OnServerEvent:Connect(function(player)
	game.ReplicatedStorage.DialogEnd.OnServerEvent:Connect(function(character)
	
	
		player.character.Humanoid.WalkSpeed = 16
		player.character.Humanoid.JumpPower = 50

	end)
	end)

P.S. Still learning how to code, so apologies about my rookie mistakes.

4 comments

0

That should be correct unless you didnt set a parameter to player in the local script

0

also why do you have two OnServerEvent for the same RemoteEvent?

0

Oh 'cuz I'm tryin' to find the player, then the character of the player, then the humanoid of the player's character, if that makes any sense. :)

0

You should remove the second one it doesnt do anything besides give the player

1 answer

✓ Accepted answer

see if this helps you out

game.ReplicatedStorage.DialogEnd.OnServerEvent:Connect(function(player)
        player.Character.Humanoid.WalkSpeed = 16
        player.Character.Humanoid.JumpPower = 50
end)

the remote event ONLY pass the player instance, not the character instance, unless the local script pass the char through a second argument

something like this

local plr = game.Players.LocalPlayer
local char = plr.Character

game.ReplicatedStorage:FindFirstChild("DialogEnd"):FireServer(char) -- always use find first child when firing a remote event that's not a descendant of the local script

then this:

game.ReplicatedStorage.DialogEnd.OnServerEvent:Connect(function(player,char)
        char.Humanoid.WalkSpeed = 16
        char.Humanoid.JumpPower = 50
end)

would work, because you're now passing the character argument through the local script, see more about remote events at: https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

hope this helps

5 comments

0

it might have some typos because i wrote it directly by this website

0

Getting an error: Attempt to index nil with "humanoid" ?

0

hmm, what line ?

0

Line 2.

0

Nvm, didn't modify the local script.. Stupid mistake from my side. Now it works! Thank you so much! :)

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