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

How I can fix a error to can reffering to a player team?

Asked by 7 years ago
Edited 7 years ago

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?

01TeamA = game.Workspace.TeamPaint.TeamA
02TeamB = game.Workspace.TeamPaint.TeamB
03Paint = script.Parent
04 
05script.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
10end)

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

You never defined Player. Use the GetPlayerFromCharacter function.

1--code
2script.Parent.Touched:connect(function(hit)
3    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
4    if not Player then return end
5    --code
6end)
Ad
Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
7 years ago
Edited 7 years ago

Here, I'll give ya a tip!

01TeamA = game.Workspace.TeamPaint.TeamA
02TeamB = game.Workspace.TeamPaint.TeamB
03Paint = script.Parent
04 
05script.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
12end)

If this works, please mark as the correct answer! <3

As always, good scripting!

Answer this question