I’m trying to make a script that changes the player’s WalkSpeed through a script when a round starts. (Not a localscript)
I’ve tried many different methods but none have worked.
Current method I’m trying:
local function SpinnerWalkSpeed(plr)
local humanoid = plr.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 80
end
end
local function DefaultWalkSpeed(plr)
local humanoid = plr.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end
Characters aren’t ancestors of their Player instances. However, Player instances do have a Character property which refers to their character model, so you’ll want to do this to define the humanoid instead:
local humanoid = plr.Character and plr.Character:FindFirstChildOfClass("Humanoid")
You can use a for loop to loop through every player.
The script would look like this:
local function SpinnerWalkSpeed(plr)
local humanoid = plr.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 80
end
end
local function DefaultWalkSpeed(plr)
local humanoid = plr.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end
for i, v in pairs(game.Players:GetChildren()) do
--Your function here
end
local rep = game:GetService("ReplicatedStorage")
local SpinnerWalkSpeed = rep.WalkSpeedEvents:WaitForChild("SpinnerWalkSpeer")
local DefWalkSpeed = rep.WalkSpeedEvents:WaitForChild("DefWalkSpeed")
SpinnerWalkSpeed.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char.Humanoid
h.WalkSpeed = 0
h.JumpPower = 80
end)
DefWalkSpeed.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char.Humanoid
h.WalkSpeed = 16
h.JumpPower = 50
end)
local function SpinnerWalkSpeed(plr)
local humanoid = plr.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 80
end
end
local function DefaultWalkSpeed(plr)
local humanoid = plr.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end
In the script shown above, how are you passing the arguments through to the functions?
Sorry for the wait! Been busy.
This doesn’t seem to be working… The character’s walkSpeed is not changing. There is nothing in the output. ( it is also not printing.)