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

How do I make a brick which changes team and kills the player?

Heres my code it hasnt worked though, (help).

tm = script.Parent

function onTouched(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h ~= nil then local n = hit.Parent local p = game.Players:FindFirstChild("Level2") if p ~= nil then p.TeamColor = tm.BrickColor end end end

script.Parent.Touched:connect(onTouched)

2 comments

0

(On touch)

0

Your script is looking for "Level2" in game.Players. That is probably your mistake. WIth this script you would want to make it like game.Players:FindFirstChild(hit.Parent.Name). Try GetPlayerFromCharacter

1 answer

✓ Accepted answer

your script looks for a specific player and doesn't generalize to accommodate other players

you could simply just do this:

local team_changer = workspace.etc -- put here the directory of the part that changes the team

team_changer.Touched:Connect(function(part)
	local parent = part.Parent
	local player;	

	if parent then
		player = game.Players:GetPlayerFromCharacter(parent)
		
		if player then
			player.TeamColor = Brickcolor.new("Really red") -- change "really red" to a desire roblox color

		end
	end
end)

so the above code listens to when the the part stored in team_changer is touched; then declares a variable parent to get the parent of the part that touched the team changer, then declares player and sets it to nil, next: it checks if the parent is there then assigns player to the corresponding Player object in Players Service from the character model stored in player

1 comment

0

Terrible usage of semicolons. If you are going to use them, use them on every line that isn't a loop starter or statement/function starter.

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