Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Team change on touch script swapping both teams?

For my Jailbreak game, the script is only meant to make Prisoners criminals, but it's changing both. Here's my script:

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		if game.Players[humanoid.Parent.Name].Team == game.Teams.Prisoner then
			game.Players[humanoid.Parent.Name].Team = game.Teams.Criminal
		end
	end
end)

what is wrong with it? Bit of help plz - this is going towards the How to make Jailbreak series on YouTube! Thanks!

1 answer

Instead of searching for the player in game.Players, why not just use GetPlayerFromCharacter instead, also I think u need to change the teamcolor of the player to the team.TeamColor

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
     if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
       if not player then return end
          if player.Team == game.Teams.Prisoner then
             player.Team = game.Teams.Criminal
             player.TeamColor = game.Teams.Criminal.TeamColor
           end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.