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

leaderstats script not working in game but fine in studio?

Asked by 6 years ago

this script works perfectly in studio, but when i test on a server. Whats wrong with it?

game.Players.PlayerAdded:connect(function(player)
    local leaderstat = Instance.new("Model")
        leaderstat.Parent = player
        leaderstat.Name = "leaderstats"


    local ROBUX = Instance.new("IntValue")
    ROBUX.Name = "CashDonated"
    ROBUX.Parent = game.Players.LocalPlayer.leaderstats
    ROBUX.Value = 0


    local PlayTime = Instance.new("IntValue")
    PlayTime.Parent = leaderstat
    PlayTime.Value = 0
    PlayTime.Name = "Play Time"
    local i = 0
    while true do
        i = i + 1
        PlayTime.Value = i
        wait(1)

    end
end)
0
You can't use LocalPlayer in a Server Script, and leaderstats are kind of need to be run in a Server Script... Line 9, all you need is ROBUX.Parent = leaderstat M39a9am3R 3210 — 6y
0
You can also set a parent without setting it like .Parent by putting it after the instance name with a coma. In this case: Instance.new("IntValue", leaderstat), the leaderstat was already assigned parent to the player, so you could've assigned it to that instead. User#18043 95 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
game.Players.PlayerAdded:connect(function(player)
    local leaderstat = Instance.new("Model")
        leaderstat.Parent = player
        leaderstat.Name = "leaderstats"


    local ROBUX = Instance.new("IntValue")
    ROBUX.Name = "CashDonated"
    ROBUX.Parent = leaderstat
    ROBUX.Value = 0


    local PlayTime = Instance.new("IntValue")
    PlayTime.Parent = leaderstat
    PlayTime.Value = 0
    PlayTime.Name = "Play Time"
    local i = 0
    while true do
        i = i + 1
        PlayTime.Value = i
        wait(1)

    end
end)

Ad
Log in to vote
0
Answered by 6 years ago

You didn't have to refer to LocalPlayer in a server script. Only LocalScript can refer to LocalPlayer. Also, you didn't need to put it like that, the leaderstats was already parented to player so it would've been faster to put it like this:

ROBUX.Parent = leaderstat

Full script:

game.Players.PlayerAdded:connect(function(player)
    local leaderstat = Instance.new("Model")


        leaderstat.Parent = player
        leaderstat.Name = "leaderstats"
    local ROBUX = Instance.new("IntValue")


        ROBUX.Name = "CashDonated"
        ROBUX.Parent = leaderstat
    ROBUX.Value = 0


    local PlayTime = Instance.new("IntValue")
    PlayTime.Parent = leaderstat
    PlayTime.Value = 0
    PlayTime.Name = "Play Time"
    local i = 0
    while true do
        i = i + 1
        PlayTime.Value = i
        wait(1)
    end
end)
0
Dude, i answered first, and my answer works. Void_Frost 571 — 6y

Answer this question