Why won't this script change the value of a Humanoid's Walkspeed?

Hi, I’m making a script that changes a Humanoids walkspeed if they are on a team.

The problem is, it won’t change it in the while loop, I checked and the humanoid walkspeed is at 30, and the player is on the team, there are no errors in the console.

script.Parent.Humanoid.MaxHealth = 750
script.Parent.Humanoid.WalkSpeed = 30
script.Parent.Humanoid.Health = script.Parent.Humanoid.MaxHealth
game.Players.PlayerAdded:Connect (function(player)
	while player.Team == game.Teams.SCPS do
		script.Parent.Humanoid.WalkSpeed = 0
		wait(5)
		script.Parent.Humanoid.WalkSpeed = 30
		wait(4)
	end
end)

player.Team isn’t based off of the team object. It’s based off the BrickColor (I’m not sure why either).

1 Like

even when I do

while player.Team == BrickColor.new("Bright red") do

it won’t work with no errors

Try player.TeamColor and BrickColor.Red().

1 Like
local Team = game:GetService("Teams")["SCPS"]

for _, player in pairs(game.Players:GetPlayers()) do
	while player.Team == Team do
		script.Parent.Humanoid.WalkSpeed = 0
		wait(5)
		script.Parent.Humanoid.WalkSpeed = 30
		wait(4)
	end
end
1 Like
script.Parent.Humanoid.MaxHealth = 750
script.Parent.Humanoid.WalkSpeed = 30
script.Parent.Humanoid.Health = script.Parent.Humanoid.MaxHealth
game.Players.PlayerAdded:Connect (function(player)
	while player.TeamColor == BrickColor.Red() do
		print("Hi")
		script.Parent.Humanoid.WalkSpeed = 0
		wait(5)
		script.Parent.Humanoid.WalkSpeed = 30
		wait(4)
	end
end)

led to same result, this time I put a print statement to check if the error is from that, and the print isn’t printing so it is.

local Team = game:GetService(“Teams”)[“SCPS”]

local Players = game:GetService(“Player”)
function PlayedAdded(Player)
local function CharacterAdded(Character)
repeat wait() until Character:IsDescendantOf(workspace)
while Player.Team == Team do
Player.Character.Humanoid.WalkSpeed = 0
wait(5)
Player.Character.Humanoid.WalkSpeed = 30
wait(4)
end
end
Player.CharacterAdded:connect(CharacterAdded)
end
Players.PlayerAdded:connect(PlayedAdded)

for _,Player in pairs(Player:GetPlayers()) do
PlayerAdded(Player)
end

I am not sure if this is what you are looking for.

1 Like