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)
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
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
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