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

How to change walkspeed of a player in a remote event?

as the title says, how can i do it? I tried using something like this script:

game.Workspace[player.Name].Humanoid.WalkSpeed = 0

inside this script in a remoteEvent:

game.Workspace.RemoveGamaboiEvent.OnServerEvent:Connect(function(player)
game.Players[player.Name].Backpack.Gamaboi:remove()
game.Workspace[player.Name].Humanoid.WalkSpeed = 0
end)

Commanded by a localscript that triggered the remoteEvent

clickdetector3.MouseClick:Connect(function()
	game.Workspace.GamaboiEvent:FireServer()
end)

However, no result was given.

Can us help me?

2 answers

✓ Accepted answer

I made a server - sided(normal) script, and a client - sided(local) script. The script is to be parented to ServerScriptService, the local script is to be paranted to the clickdetector, and the RemoteEvent is to be parented to ReplicatedStorage.

--Server - sided script

local re = game.ReplicatedStorage.GamaboiEvent

re.OnServerEvent:Connect(function(player)
        player.Character.Humanoid.WalkSpeed = 0
        if player.Backpack:FindFirstChild('Gamaboi') then
               player.Backpack.Gamaboi:Destroy()
        end
end)
--Client - sided script

local re = game.ReplicatedStorage.GamaboiEvent
local player = game.Players.LocalPlayer

script.Parent.MouseClick:Connect(function()
       re:FireServer()
end)

Firstly, a LocalScript will only work in:

  1. PlayerScripts
  2. Character
  3. PlayerGui
  4. Backpack
  5. ReplicatedFirst

so do this:

LocalScript in StarterPlayerScripts

clickdetector3.MouseClick:Connect(function()
	game.Workspace.GamaboiEvent:FireServer()
end)

Script

game.Workspace.RemoveGamaboiEvent.OnServerEvent:Connect(function(player)
	player.Backpack.Gamaboi:Destroy()
	player.Character.Humanoid.WalkSpeed = 0
end)

Firstly, player is a parameter, so it's already there. No need to try and find it inside Players. Also, never find the character by their name, inside the workspace. There's a property called Character.

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