Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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.

0
forget that second block on the Ex. Gusookey -3 — 6y

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?

3 answers

Log in to vote
0
Answered by 6 years ago
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..

Ad
Log in to vote
0
Answered by
dionant 23
6 years ago

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)
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) GrandNebula 14 — 6y
Log in to vote
0
Answered by 6 years ago

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 ServerScriptServiceor 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