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

Need Help making a block that changes to your team color when you touch on it.Any Ideas?

I am trying to make a block that changes color to the color of the team they are.Ex.You are on blue team and you step on a block that block changes to Team color Blue.

1 comment

0

forget that second block on the Ex.

3 answers

local Brick = script.Parent
local function PlayerTouched(Part)
	local plr = game.Players.LocalPlayer
	Brick.Color = plr.TeamColor
end

Brick.Touched:connect(PlayerTouched)

i tried, hope this helps, if this works feel free to accept answer..

That code won't work because LocalPlayer won't work.

local function Touched(Part)
local Player = Part.Parent:GetPlayerFromCharacter() -- Instead of localplayer, we find the parent of the touched bodypart (the player's character model in workspace) and use GetPlayerFromCharacter() to define the Player
script.Parent.Color = Player.TeamColor
end


script.Parent.Touched:connect(Touched)

1 comment

0

This code won't work because it will return the error that GetPlayerFromCharacter is not a valid property of model. You have to go through the player. Like this: game.Players:GetPlayerFromCharacter(Part.Parent)

So, the way to go about doing this is using TeamColor, Touchedevent, GetPlayerFromCharacter, and parameters. I recommend you take a look at the wiki links I leave at the bottom of this answer to make sure you learn something from this!

This is a normal script, that should be placed in ServerScriptService or Workspace.

local Brick = game.Workspace.Brick -- Change this to the location of the part 

Brick.Touched:Connect(function(hit) -- Makes a function that occurs when Brick is touched
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player in game.Players 			using the model of the player in Workspace
	
	Brick.BrickColor = Player.TeamColor
end)

I recommend adding a debounce, and several WaitForChild's to make sure that what is touching the Brick is a player. These are whole other topics, though.

[Links]

[1] TeamColor

[2] Touched Event

[3] GetPlayerFromCharacter

[4] Arguments/Parameters

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