09-04-2012, 02:15 PM
I'm trying to add two IntegerValues to the (only - SP game) player's Stats object, but it doesn't seem to work unless I run the script manually with the right-click menu. I've Enabled it, and tried it under World and Players, yet nothing happens. It yields no errors.
I'd appreciate it if someone could check this and tell me if anything's wrong.
I'd appreciate it if someone could check this and tell me if anything's wrong.
Code:
link(game.Players.ChildAdded, function(p)
if p.Type == "Player" then
local score = create("IntegerValue")
score.Name = "Score"
local hiscore = create("IntegerValue")
hiscore.Name = "Hi-Score"
score.Parent = p.Stats
hiscore.Parent = p.Stats --*nothing* happens after all this. Can't even see values in leaderboard.
end
_G.score = function(a) --attempting to use these globals tells me the script tried to reference nil, presumably due to player not being defined.
if p.Stats.Score then
local lescore = p.Stats.Score.Value
local lehiscore = p.Stats["Hi-Score"].Value
lescore = lescore + a
if lescore > lehiscore then
lehiscore = lescore
end
end
end
_G.reset = function()
if p.Stats.Score then
p.Stats.Score.Value = 0
end
end
end)