I am trying to make a script that when a player hits a block it changes to the player team color but It doesnt work. Can somebody see it and try to help me?
01 | TeamA = game.Workspace.TeamPaint.TeamA |
02 | TeamB = game.Workspace.TeamPaint.TeamB |
03 | Paint = script.Parent |
04 |
05 | script.Parent.Touched:connect( function () |
06 | script.Parent.BrickColor = Player.TeamColor |
07 | wait( 0.2 ) |
08 | game.Workspace.TeamA = game.Workspace.TeamA + 1 |
09 | Player.leaderboard.Paint.Value = Player.leaderboard.Paint.Value + 1 |
10 | end ) |
You never defined Player
. Use the GetPlayerFromCharacter function.
1 | --code |
2 | script.Parent.Touched:connect( function (hit) |
3 | local Player = game.Players:GetPlayerFromCharacter(hit.Parent) |
4 | if not Player then return end |
5 | --code |
6 | end ) |
Here, I'll give ya a tip!
01 | TeamA = game.Workspace.TeamPaint.TeamA |
02 | TeamB = game.Workspace.TeamPaint.TeamB |
03 | Paint = script.Parent |
04 |
05 | script.Parent.Touched:connect( function (hit) --Get what made the hit. |
06 | --Define player's variable here with the method GetPlayerFromCharacter! |
07 | local Player = game.Players:GetPlayerFromCharacter(hit.Parent) |
08 | script.Parent.BrickColor = Player.TeamColor |
09 | wait(. 2 ) |
10 | game.Workspace.TeamA = game.Workspace.TeamA + 1 |
11 | Player.leaderboard.Paint.Value = Player.leaderboard.Paint.Value + 1 |
12 | end ) |
If this works, please mark as the correct answer! <3
As always, good scripting!