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

Leaderboard Shop not working?

Asked by 8 years ago

So... in my game I used the leaderboard as currency ("Points"). Then I made a Part that if you step on it it will check if you have enough then subtract the price from your points. If you don't have enough, it would clone a GUI from Server Storage and send it (change the parent) into the PlayerGui in Players. It works perfectly in Studio but doesn't work in ROBLOX Player. Why is this?

This is the code:

script.Parent.Touched:connect(function()
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            if Player.leaderstats.Points.Value >= script.Parent.Price.Value then
        Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - script.Parent.Price.Value
        game.ServerStorage.Tools["Blue Torch"]:Clone().Parent = game.Players.LocalPlayer.Backpack
    else
        game.ServerStorage.GUI["Not enough"]:Clone().Parent = game.Players.LocalPlayer.PlayerGui
        wait(5)
        game.Players.LocalPlayer.PlayerGui["Not enough"]:Destroy()
    end
        end
    end
end)

2 answers

Log in to vote
0
Answered by
Uglypoe 557 Donator Moderation Voter
8 years ago

Clients cannot access ServerStorage, and you are using game.Players.LocalPlayer meaning it's a local script in the client. You will have to send a request to a server script with RemoteEvents so that the server can clone the guy to other players.

Ad
Log in to vote
0
Answered by
Cuvette 246 Moderation Voter
8 years ago

It's possible you need,

Player:WaitForDataReady()

to ensure the player is fully loaded in before you start accessing their values. If that doesn't work, you could try putting it into a Localscript, I've made some modifications below

script.Parent.Touched:connect(function()
    local Player = game.Players.LocalPlayer
        if Player:FindFirstChild("leaderstats") then
            if Player.leaderstats.Points.Value >= script.Parent.Price.Value then
        Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - script.Parent.Price.Value
        game.ServerStorage.Tools["Blue Torch"]:Clone().Parent = Player.Backpack
    else
        game.ServerStorage.GUI["Not enough"]:Clone().Parent = Player.PlayerGui
        wait(5)
        Player.PlayerGui["Not enough"]:Destroy()
        end
    end
end)
0
It's a touched function. I'm pretty sure data is loaded farrrrr before you would walk around and touch a part. Good thought but inaccurate. Uglypoe 557 — 8y

Answer this question