Remove player walkspeed script

My goal is to freeze a player during a count down. But i cant make my script work. I you could help i would appreciate it. Thank you


game.Players.PlayerAdded:Connect(function(plr) -- This detects a player entering the game, and assigns the variable plr to him.
	plr.CharacterAdded:Connect(function(character) -- Detects character.
		local humanoid = character:FindFirstChild("Humanoid")


		game.ReplicatedStorage.FreezePlayer.OnClientEvent:Connect(function()
			print("Working to freeze players")
			if humanoid then
				humanoid.WalkSpeed = 0
			end
			
			
		end)
		
		
		game.ReplicatedStorage.MovePlayer.OnClientEvent:Connect(function()

			if humanoid then
				humanoid.WalkSpeed = 16
			end


		end)

		
		
		
		



	end)
end)
4 Likes

This is local script yea?
If so you don’t have to use PlayerAdded function just call player

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

--The rest of the code
2 Likes

Its still not working, is it bc its in serverscript service

1 Like

So when player joins the game it freeze the player for a few seconds before went normal?

Oh this is server script if so you should change OnClientEvent to OnServerEvent
I mean it is server it can’t use OnClientEvent
Ah wait this is local script but you put it in server script service? You should place it in StarterCharacterScript

1 Like

Its in server script service in a local script

1 Like

There is a timer for 5 second that starts, and during those 5 seconds, the players cant move

1 Like

why would you even have a LocalScript in ServerScriptService
that makes no sense

1 Like

i dont know where to put the script

1 Like

I said to put it in StarterCharacterScript ;-;

1 Like
local Humanoid = Char:FindFirstChild("Humanoid")

if Humanoid then
Humanoid.Walkspeed = 0
task.wait(5)
Humanois.Walkspeed = 16
end

Try this one inside the function

2 Likes

You should do something like this, in a local script in StarterCharacterScript.
You can also do it without remote events by just detecting the cooldown value which change in server side.

Edit: Oops sorry renly, the reply is a missclick

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local FreezePlayer = ReplicatedStorage:WaitForChild("FreezePlayer", 30)
local MovePlayer = ReplicatedStorage:WaitForChild("MovePlayer", 30)

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid", 30)

if Humanoid and FreezePlayer and MovePlayer then
	FreezePlayer.OnClientEvent:Connect(function()
		Humanoid.WalkSpeed = 0
	end)
	MovePlayer.OnClientEvent:Connect(function()
		Humanoid.WalkSpeed = 16
	end)
end
1 Like

What is the 30 for the one in ()

1 Like

If the script the that fires the remote event is in server script service, do i do fireclient or fireallclients?

1 Like

It is a small wait time, just a security to avoid the script infinitely waiting or the script running when objects aren’t found.

1 Like

If the script the that fires the remote event is in server script service, do i do fireclient or fireallclients?

1 Like

If the freeze need to apply for all players, then use FireAllClients, if it apply for only one player, use FireClient.

2 Likes

ok thanks, ill let u know if it works

1 Like

It works thank you, one last thing, how do i make so the players cant jump also

1 Like

Np, you can add this in your functions

Humanoid.JumpPower = 0
1 Like