My scripts
I have a script here, which I think should work, but does not:
local Players = game:GetService("Players")
local function onPlayerAdded(plr)
local char = plr.Character
if char then
local hum = char.Humanoid
hum.WalkSpeed = 0
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
local Players = game:GetService("Players")
local function onPlayerAdded(plr)
pcall(function()
repeat until plr.Character and plr.Character.Humanoid
plr.Character.Humanoid.WalkSpeed = 0
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Just added a repeat loop to wait for the Humanoid and Character, as well as added a pcall just in case the humanoid doesn’t exist.
I believe this script is better for performance due to it only firing once.
local Players = game:GetService("Players")
local function onPlayerAdded(plr)
pcall(function()
plr.CharacterAdded:Wait() -- yields the thread until the character is added
plr.Character.Humanoid.WalkSpeed = 0
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)`
local Game = game
local Players = Game:GetService("Players")
local function OnPlayerAdded(Player)
local function OnCharacterAdded(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid", 5)
if not Humanoid then return end
Humanoid.WalkSpeed = 0 --Freeze movement.
end
Player.CharacterAdded:Connect(OnCharacterAdded)
end
Player.CharacterAdded:Connect(OnPlayerAdded)
No need for pcall(), which has a considerably poor overhead.