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

How do I make it so if a player in a specific team touches this block , it changes their team ?

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)

1 comment

0

If Player.Team == game.Teams.Prisoner then Player.Team = game.Teams.Criminal

1 answer

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)

4 comments

0

wym there's a 50 50 chance of being an npc or a player

0

Where would I input what team the prisoner will change to (criminal in this case) ?

0

Yeah, simply change "Prisoner" to "Criminal"

0

And please accept if this helped

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