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.
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)
So, the way to go about doing this is using TeamColor
, Touched
event, 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
Closed as Not Constructive by Perci1
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?