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

Why does it not change my team when I touch the block?

local team = game.Teams.Lobby
local function ontouch(part)
	local hum = part.Parent:FindFirstChild("Humanoid")
	local players = game.Players:GetChildren()
	if players then
	if hum then
		players.Teams = game.Teams.Lobby
		hum.Health = 0
		end
	end
end
script.Parent.Touched:connect(ontouch)

IDK whats the problem here.

2 answers

✓ Accepted answer

You added an s to the property Team. It's also best to use GetPlayerFromCharacter, as it's shorter.

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent) --gets the players' character
	if player then --if the player touched it then
	player.Team = game.Teams.Lobby --change the team
	player.Character.Humanoid.Health = 0 --get the humanoid and set it's health to 0
else return end
end)

Please accept my answer if this helped!

You need to define the actual player, not just list. Team should be TeamColor

local team = game.Teams.Lobby
local function ontouch(part)
	local hum = part.Parent:FindFirstChild("Humanoid")
	local player = game.Players:findFirstChild(hum.Parent.Name)
	if hum then
		if player then
			player.TeamColor = team.TeamColor
			hum.Health = 0
		end
	end
end
script.Parent.Touched:connect(ontouch)

That will change the Team of the player who touches the brick.

Let me know if this isn't the solution you were looking for.

2 comments

0

You could just use player.Team = team

0

so like player.team = team?

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