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

Team Change BUTTON possible?

is it possible to make a button that when you touch it it changes your team? If yes then is this correct??

function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
humanoid.SetTeam("Fire")
end
end
script.Parent.Touched:connect(onTouch)

4 comments

0

yes

0

is this correct?

0

'If yes then is this correct?' - can you not test it yourself?

0

Good

1 answer

✓ Accepted answer

The best way to do this would be:

script.Parent.Touched:connect(function(h)
	local plr = game.Players:GetPlayerFromCharacter(h.Parent) --this will get the actual player object from the character, since h would typically be like a body part, such as Head, and head.Parent = the player's character.
	if plr then --checking to see if it actually is a player
		plr.Team = game.Teams["Fire"] --if so proceed to make their team the "Fire" team.
	end
end)

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