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 6 years ago
Edited 6 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?

TeamA = game.Workspace.TeamPaint.TeamA
TeamB = game.Workspace.TeamPaint.TeamB
Paint = script.Parent

script.Parent.Touched:connect(function()
    script.Parent.BrickColor = Player.TeamColor
    wait(0.2) 
    game.Workspace.TeamA = game.Workspace.TeamA + 1
    Player.leaderboard.Paint.Value = Player.leaderboard.Paint.Value + 1
end)

2 answers

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

You never defined Player. Use the GetPlayerFromCharacter function.

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

Here, I'll give ya a tip!

TeamA = game.Workspace.TeamPaint.TeamA
TeamB = game.Workspace.TeamPaint.TeamB
Paint = script.Parent

script.Parent.Touched:connect(function(hit) --Get what made the hit.
    --Define player's variable here with the method GetPlayerFromCharacter!
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    script.Parent.BrickColor = Player.TeamColor
    wait(.2) 
    game.Workspace.TeamA = game.Workspace.TeamA + 1
    Player.leaderboard.Paint.Value = Player.leaderboard.Paint.Value + 1
end)

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

As always, good scripting!

Answer this question