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

Why isnt this player script working? NOT ANSWERED

Asked by
TrollD3 105
9 years ago

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 :

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 
--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
end
end)
end)
end)

--I made another script because of the possible error I could have made, but it still doesn't work. 
-- Perci said something about the score value and stuff so I gave it a shot. But it doesn't work.
game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = player
     local Score = Instance.new("IntValue") --We create a new IntValue
     Score.Name = "Score" --this is the name you want the leader-stat to be when it shows up in-game.
     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)
     Score.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
 end)

1
Is this a LocalScript? PlayerAdded and CharacterAdded, as well as the Died event, don't always work properly in LocalScripts. adark 5487 — 9y
0
Is 'Score' an IntValue in the Team object or something? Perci1 4988 — 9y
0
isnt score a property of a team? So would I have to make that an int value? And if I did, I would put it in players i assume? TrollD3 105 — 9y
0
No, there is no Score property. Look this stuff up. Perci1 4988 — 9y
View all comments (2 more)
0
Me and someone else already answered this question you deleted... alphawolvess 1784 — 9y
0
Ik. I changed it. And it still doesnt work. TrollD3 105 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I see a few problems with this script, and I will attempt to fix them

game.Players.PlayerAdded:connect(function(Player) --good
Player.CharacterAdded:connect(function(Char) --good
Char:WaitForChild("Humanoid").Died:connect(function()--See comment 1 
if Player.TeamColor == BrickColor.new("Camo") then --good unless "Camo" doesn't exist
game.Teams.Sentinel.Score = game.Teams.Sentinel.Score + 1 --See Comment 2
script.Parent.Text = game.Teams.Sentinel.Score --See comment 2
elseif Player.TeamColor == BrickColor.new("Bright red") then --good
game.Teams.Atlas.Score = game.Teams.Atlas.Score + 1 --See comment 2
script.Parent.Parent.Atlas.Text = game.Teams.Atlas.Score --See comment 2
end
end)
end)
end)

Comment 1 It is unnecessary to WaitForChild because I figure that the Char will have plenty of time to load before it can die Comment 2 I'm figuring that Score is a "IntValue" or "NumberValue". This means that Score is the Instance that contains the value, not the value itself so doing:

game.Teams.Sentinel.Score.Value = game.Teams.Sentinel.Score.Value + 1
~~~~~~~~~~~~~~~~~'
would be more appropriate.
**NOW TO FIX THE SECOND PART OF YOUR QUESTION**
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

Ad

Answer this question