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

So I have this script where the GUI says the cash amount that the leaderstat says?

Asked by 3 years ago

I want it so there is no cash stat in the leaderboard but to have it just in the GUI The scripts: Serverscript:

game.Players.PlayerAdded:Connect(function(plr) 
    local leaderstats = Instance.new("Folder")  
    leaderstats.Parent = plr  
    leaderstats.Name = "leaderstats" 

    local cash = Instance.new("IntValue")
    cash.Parent = leaderstats
    cash.Name = "Cash"

    cash.Value = 0

    while wait(60) do
        cash.Value = cash.Value + 50
    end
end)

The local script:

local textLabel = script.Parent.Frame.TextLabel
local cash = game.Players.LocalPlayer.leaderstats.Cash

cash.Changed:Connect(function()
    textLabel.Text = "Cash: "..cash.Value
end)

1 answer

Log in to vote
0
Answered by
KingDomas 153
3 years ago

Server Script (using a datastore script i made for a previous game):

local datastore = game:GetService("DataStoreService")
local players = game:GetService("Players")
local getMoney = datastore:GetDataStore("money")
local money = Instance.new("IntValue")

local function onPlayerAdded(player)
    local playerKey = "Player_" .. player.UserId

    local stats = Instance.new("IntValue")
    stats.Name = "Stats"

    money.Name = "Money"
    money.Parent = player
end

for _, player in pairs(players:GetPlayers()) do
    onPlayerAdded(player)
end
players.PlayerAdded:Connect(onPlayerAdded)

wait(1)
while wait(0.1) do
    getMoney:SetASync(myMoney)
    money.Value = tonumber(myMoney)
end

Local Script

local player = game.LocalPlayer.Name
local textLabel = script.Parent.Frame.TextLabel
local cash = game.Workspace[player].Money

cash.Changed:Connect(function()
    cash.Text = "Cash: "..cash.Value
end)
Ad

Answer this question