I done a script when a player touch a block if he is in a determined team, the team will add a +1 to TeamA or B but when I touch the block it doesnt work. What can be the trouble?
local TeamA = Instance.new("NumberValue") TeamA.Name = ("TeamA") TeamA.Value = 0 TeamA.Parent = workspace local TeamB = Instance.new("NumberValue") TeamB.Name = ("TeamB") TeamB.Value = 0 TeamB.Parent = workspace 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) if Player.team == game.Teams.TeamA then game.Workspace.TeamA = game.workspace.TeamA.Value + 1 Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1 end if Player.team == game.Teams.TeamB then game.workspace.TeamB = game.workspace.TeamB.Value + 1 Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1 end end)
I know what's going on.
A thing I learned recently: When there's a .Touched event, the LocalScript / Script NEEDS to be putted in the StarterGui. Other thing, I don't really like using NumberValues, I would recommend you using IntValues. Having said that, here's what you want:
local TeamA = Instance.new("IntValue") --Change to IntValue. TeamA.Name = "TeamA" --Remove the () TeamA.Value = 0 TeamA.Parent = game.Workspace --Make sure he knows what's workspace. local TeamB = Instance.new("IntValue") --Change to IntValue. TeamB.Name = "TeamB" --Remove the () TeamB.Value = 0 TeamB.Parent = game.Workspace --Make sure he knows what's workspace. 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): This works, but there's another way I prefer. local Character = hit.Parent.Name local Player = game.Players[Character] if hit.Parent:FindFirstChild("Humanoid") then --Check if it's a player. script.Parent.BrickColor = Player.TeamColor --In here you're saying Brick's Color should be the Player's TeamColor. I think what you want is the opposite. I didn't change that, but if what you want is CHANGE THE PLAYER'S TEAMCOLOR *TO* THE BRICK'S COLOR, then swap the variables there up. wait(.2) end if Player.Team == game.Teams.TeamA then game.Workspace.TeamA = game.Workspace.TeamA.Value + 1 Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1 --leaderboard? try like this, but if it won't work, switch 'leaderboard' with 'leaderstats'. elseif Player.Team == game.Teams.TeamB then game.Workspace.TeamB = game.Workspace.TeamB.Value + 1 Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1 --leaderboard? try like this, but if it won't work, switch 'leaderboard' with 'leaderstats'. end end)
After 2 hours, here's your script there up ^^
If this solves your problem, please mark as the solution.
As always, good scripting!