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

Why isnt this player died script working?

Asked by
TrollD3 105
9 years ago

I have been working on the same script now to no avail. It hurts my head so much and makes me want to quit. All I want to do is basically do this: - if a player is on "team 1" and they kill a player from "team 2", their team gets +1 added to the score they have ( ex. If score is 1 , another kill would make it = 2 and etc..) Im trying to do the above and also add if "team 2" kills a player from "team 1", they also get +1 points.

This is the script. It has no error in output but one thing i noticed was that is said unknown global player.... How would I fix that?

game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Char)
Char:WaitForChild("Humanoid").Died:connect(function()
if player.TeamColor == BrickColor.new("Camo") then --You could change this color to your own.
game.Teams.Sentinel.Score = game.Teams.Sentinel.Score + 1 
script.Parent.Text = game.Teams.Sentinel.Score.Value
--Assuming "Score" is a IntValue, then add `.Value` to it. This would give an error without it.

elseif player.TeamColor == BrickColor.new("Bright red") then --You could change this color to your own.
--What i've done is, what if the other team kills the other person? This would give them a score as well.
game.Teams.Atlas.Score = game.Teams.Atlas.Score + 1 
script.Parent.Parent.Atlas.Text = game.Teams.Atlas.Score
--Change TEAM2 to your other team, besides "Sentinel".
end
end)
end)
end)


2 answers

Log in to vote
1
Answered by 9 years ago

First you were using the variable player instead of the variable Player that you made. Second you put Score.Value.

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Char)
        Char:WaitForChild("Humanoid").Died:connect(function()
            if Player.TeamColor == BrickColor.new("Camo") then 
                game.Teams.Sentinel.Score = game.Teams.Sentinel.Score + 1 
                script.Parent.Text = game.Teams.Sentinel.Score
            elseif Player.TeamColor == BrickColor.new("Bright red") then 
                game.Teams.Atlas.Score = game.Teams.Atlas.Score + 1 
                script.Parent.Parent.Atlas.Text = game.Teams.Atlas.Score
            end
        end)
    end)
end)
0
Thanks A lot!! TrollD3 105 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

First, please tab your code correctly, it looks much better and helps us scan quicker. Second, it appears you're doing a typo, line 4 and 9 should have Player not player. Lua is sensitive to capitalization. After said edits, you should check all of your hierarchy and spelling. Also, you are doing Score.Value. You don't add a random property to something, only if Value is actually a property. So, it will actually just be Score, not Score.Value!

If this helped, accept and upvote. If not, leave a comment!

Answer this question