I am trying so hard not to rage quit on this 1 script. Its not working at all. Its not showing any errors either. Is it because I didnt add a leaderbaord to keep track of the score? Idk anymore... NOTHING WORKS....
script :
01 | game.Players.PlayerAdded:connect( function (Player) |
02 | Player.CharacterAdded:connect( function (Char) |
03 | Char:WaitForChild( "Humanoid" ).Died:connect( function () |
04 | if Player.TeamColor = = BrickColor.new( "Camo" ) then |
05 | game.Teams.Sentinel.Score = game.Teams.Sentinel.Score + 1 |
06 | script.Parent.Text = game.Teams.Sentinel.Score |
07 |
08 | elseif Player.TeamColor = = BrickColor.new( "Bright red" ) then |
09 | --What i've done is, what if the other team kills the other person? This would give them a score as well. |
10 | game.Teams.Atlas.Score = game.Teams.Atlas.Score + 1 |
11 | script.Parent.Parent.Atlas.Text = game.Teams.Atlas.Score |
12 | end |
13 | end ) |
14 | end ) |
15 | end ) |
01 | --I made another script because of the possible error I could have made, but it still doesn't work. |
02 | -- Perci said something about the score value and stuff so I gave it a shot. But it doesn't work. |
03 | game.Players.PlayerAdded:connect( function (player) |
04 | local leaderstats = Instance.new( "Model" ) |
05 | leaderstats.Name = "leaderstats" |
06 | leaderstats.Parent = player |
07 | local Score = Instance.new( "IntValue" ) --We create a new IntValue |
08 | Score.Name = "Score" --this is the name you want the leader-stat to be when it shows up in-game. |
09 | Score.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later) |
10 | Score.Parent = leaderstats -- Set the money object as a child of the leaderstats object. |
11 | end ) |
I see a few problems with this script, and I will attempt to fix them
01 | game.Players.PlayerAdded:connect( function (Player) --good |
02 | Player.CharacterAdded:connect( function (Char) --good |
03 | Char:WaitForChild( "Humanoid" ).Died:connect( function () --See comment 1 |
04 | if Player.TeamColor = = BrickColor.new( "Camo" ) then --good unless "Camo" doesn't exist |
05 | game.Teams.Sentinel.Score = game.Teams.Sentinel.Score + 1 --See Comment 2 |
06 | script.Parent.Text = game.Teams.Sentinel.Score --See comment 2 |
07 | elseif Player.TeamColor = = BrickColor.new( "Bright red" ) then --good |
08 | game.Teams.Atlas.Score = game.Teams.Atlas.Score + 1 --See comment 2 |
09 | script.Parent.Parent.Atlas.Text = game.Teams.Atlas.Score --See comment 2 |
10 | end |
11 | end ) |
12 | end ) |
13 | end ) |
Comment 1 It is unnecessary to
WaitForChild
because I figure that theChar
will have plenty of time to load before it can die Comment 2 I'm figuring thatScore
is a "IntValue" or "NumberValue". This means thatScore
is the Instance that contains the value, not the value itself so doing:
1 | game.Teams.Sentinel.Score.Value = game.Teams.Sentinel.Score.Value + 1 |
2 | ~~~~~~~~~~~~~~~~~' |
3 | would be more appropriate. |
4 | **NOW TO FIX THE SECOND PART OF YOUR QUESTION** |
5 | Besides `leaderstats` being a model, and not a `IntValue` I don't see anything wrong with this, except some inefficiencies: There are two arguments in creating an `Instance` the first one is the Instance itself, and the second one is there the Instance is placed (This is more efficient than adding another line to assign a parent) |
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("IntValue", player) leaderstats.Name = "leaderstats" local Score = Instance.new("IntValue", leaderstats) Score.Name = "Score" Score.Value = 0 end) ~~~~~~~~~~~~~~~~~ Please accept if this helped