Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
That should be correct unless you didnt set a parameter to player in the local script vortex767 20 — 3y
0
also why do you have two OnServerEvent for the same RemoteEvent? vortex767 20 — 3y
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. :) SonGohan6 85 — 3y
0
You should remove the second one it doesnt do anything besides give the player vortex767 20 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

0
it might have some typos because i wrote it directly by this website MacGames007 114 — 3y
0
Getting an error: Attempt to index nil with "humanoid" ? SonGohan6 85 — 3y
0
hmm, what line ? MacGames007 114 — 3y
0
Line 2. SonGohan6 85 — 3y
0
Nvm, didn't modify the local script.. Stupid mistake from my side. Now it works! Thank you so much! :) SonGohan6 85 — 3y
Ad

Answer this question