Changing WalkSpeed based upon a value in player

I’m making handcuffs that cuff a player depending on if they have a value “Cuffed”; stored in the player in a folder named “CuffingValues”. And changing the player’s walkspeed to 0. if the value == true. However it is not working as intended. I’ve tried doing this both on Client and ServerSide but come to no avail.

Only players on a certain team have this value. (edit)

Any help is greatly apperciated.

local player = game.Players.LocalPlayer

function cuff()
	
	if player:WaitForChild("CuffingValues").Cuffed == true then
		player.Character:WaitForChild("Humanoid").WalkSpeed = 0
		
	else
		player.Character:WaitForChild("Humanoid").WalkSpeed = 16
	end
end
cuff()
1 Like

I don’t see a problem with the script, but there could be an error in the hierarchical structure of the values. Could we see a picture of the hierarchy in the Game Explorer?

Also if that is the full script, you would have to add a wait() to wait for the character of the player to load in too. While testing, if you’re too lazy to add those in just add a wait(3) at the top or something. It would be best if you used:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

function cuff()
	
	if player:WaitForChild("CuffingValues").Cuffed == true then
		character:WaitForChild("Humanoid").WalkSpeed = 0
		
	else
		character:WaitForChild("Humanoid").WalkSpeed = 16
	end
end
cuff()

I’m adding the values to the player once they join the join the game in a folder called “CuffingValues” then creating a BoolValue named “Cuffed” and parenting it into the folder.

Tested this with the wait, but the WalkSpeed is not being changed.

local v = player.CuffingValues:WaitForChild("Cuffed")
v.Changed:Connect(function()
      if v.Value == true
      then
            player.Character:WaitForChild("Humanoid").WalkSpeed = 0
      else
            player.Character:WaitForChild("Humanoid").WalkSpeed = 16
      end
end)

let me know any errors!

1 Like

This worked, thank you so much! Would i be able to add animations using this function aswell?

You can add animations when the player is arrested (after ‘then’)

1 Like

Awesome, thank you so much for your help!

1 Like