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

Why can't I go in my leaderstat folder?

Asked by 3 years ago
Edited 3 years ago

I'm trying to make a tycoon game and I'm trying to change the money value inside the leaderstat folder. But I get errors saying "attempt nil with leaderstat" and I don't know why. Help appreciated.

More info, this is a normal script.

Dropper = workspace.Dropper

script.Parent.ClickDetector.MouseClick:Connect(function()
    local Players = game:GetService("Players")
    if Players.LocalPlayer.leaderstats.Money.Value >= 500 then
        Players.LocalPlayer.leaderstats.Money.Value = Players.LocalPlayer.leaderstats.Money.Value - 500
    else
        return
    end
    for _, v in ipairs(Dropper:GetChildren()) do
        if v:IsA("Part") then
            v.Transparency = 0
            v.CanCollide = true
        end
    end
    script.parent:Destroy()
end)
0
The LocalPlayer pointer of the Player's Service, refers to the Client's affiliated Player Instance. You're are using a Server-sided Script—it is run on the Server—which means the attributes familiar to a local environment will become foreign; the Server does not have a Player Object of its own, which is why 'LocalPlayer' returns nil. Ziffixture 6913 — 3y
0
Fortunately, with .MouseClick RBXScriptSignal of ClickDetector passes the Player that clicked the BasePart as an argument to your callback, you can use that. Ziffixture 6913 — 3y
0
Kk thanks. DocGooseYT 110 — 3y

Answer this question