Hello! I’m trying to change the player’s body colors once their team has changed, and I’m having some trouble.
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(plrchar)
while true do
wait(1)
if player.Team.Name == "Infected" then
plrchar["Body Colors"].HeadColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].TorsoColor3 = Color3.fromRGB(0,100,100)
script.Parent.Humanoid.WalkSpeed = 22
player.Backpack.punch.LocalScript.Disabled = false
script:Remove()
end
end
end)
end)
2 Likes
What exactly is the issue with the code?
2 Likes
When the team changes, it doesn’t change the body colors
1 Like
Alright, So first under the “wait(1)” statement put a print function. Like this:
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(plrchar)
while true do
wait(1)
print("Hello")
if player.Team.Name == "Infected" then
plrchar["Body Colors"].HeadColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].TorsoColor3 = Color3.fromRGB(0,100,100)
script.Parent.Humanoid.WalkSpeed = 22
player.Backpack.punch.LocalScript.Disabled = false
script:Remove()
end
end
end)
end)
If it prints ‘Hello’ then that means the script works and the issue has to likely do with how you color the body.
1 Like
Alright, it doesn’t print anything
1 Like
Then that means that part of the code isn’t running for some reason.
1 Like
Also if I were you I’d change the “while true do” to “while wait(1) do”. It is more efficient.
1 Like
I seems that it has something to do with the PlayerAdded function
1 Like
this should be a ServerScript in ServerScriptService
1 Like
Make sure the script is a server script, and is in a location like ServerScriptStorage , and remove “script:Remove()”
Check to see if that works.
Also, I would advise against using a loop like that. Something like this would probably be more efficient. (Althought I haven’t tested it)
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal('Team'):Connect(function()
local plrchar = player.Character or player.CharacterAdded:Wait()
if player.Team.Name == "Infected" then
plrchar["Body Colors"].HeadColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].TorsoColor3 = Color3.fromRGB(0,100,100)
script.Parent.Humanoid.WalkSpeed = 22
player.Backpack.punch.LocalScript.Disabled = false
end
end)
end)
Thanks for the tip, but sadly the script doesn’t work
You’ll need to change:
"script.Parent.Humanoid.WalkSpeed = 22"
to
"plrchar.Humanoid.WalkSpeed = 22"
also, player.Team.Name may be nil, which I think is what is causing your issue.
Try this instead.
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(plrchar)
while wait(1) do
if player.Team then
if player.Team.Name == "Infected" then
plrchar["Body Colors"].HeadColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightArmColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].LeftLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].RightLegColor3 = Color3.fromRGB(0,100,100)
plrchar["Body Colors"].TorsoColor3 = Color3.fromRGB(0,100,100)
plrchar.Humanoid.WalkSpeed = 22
-- this line may error if the "punch" tool is not in the player's backpack, be careful.
player.Backpack.punch.LocalScript.Disabled = false
end
end
end
end)
end)
1 Like
It seems that the PlayerAdded function isn’t firing
1 Like
Make sure there’s no errors in console, and
Ensure your script is both a Server Script and inside ServerScriptStorage
besides that, maybe go deeper into how you’re debugging/there may be external factors
2 Likes
Oh, it needed to be in serverScriptStorage, thanks for the help
2 Likes
system
(system)
Closed
December 16, 2023, 11:16pm
16
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.