Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.