Hello , I am trying to make it so if a player in the 'Prisoner' team (only) hits the block it will change their team to 'Criminal' . Heres what ive attempted so far: (Bare with me , I am pretty new to coding) Help would be greatly appreciated:)
function Touch(hit) for i,v in pairs(game.Teams["Prisoner"]:GetPlayers())do player.Team = game.Teams.Criminal end end)
Ok, you need to understand the basics of the Touched event in order to continue. So, first of all, you want to check if it's a humanoid that touched it, and only players and NPCs have humanoids, so you have a 50/50 chance of it being a player. And now you want to check if the humanoid is a child of the player's character, then check what team they're in, and set the team to the specified team you'd like
local Teams = game:GetService("Teams") function Touched(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local ChangedTeam = "Prisoner" if player.Team ~= Teams[ChangedTeam] then player.Team = Teams[ChangedTeam] end end end end Part.Touched:Connect(Touched)