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

Save button doesn't save your data when clicking on it?

Asked by 6 years ago

I'm trying to make a save button that saves your data when you press it but it doesn't work..

Here's the code:

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("MoneyDataStore")

game.Players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder", player)
    folder.Name = "PlayerData"
    local moneyStats = Instance.new("IntValue", folder)
    moneyStats.Name = "moneyAmount"
    moneyStats.Value = ds1:GetAsync(player.UserId) or 0
    local saves = coroutine.create(function()
        --//Save Button 
            local saveiconbutton = game.StarterGui.MenuGUI.SaveIconButton
            local moneyStats = player.PlayerData.moneyAmount
            saveiconbutton.MouseButton1Click:connect(function()
                print("you pressed the button!")
                ds1:SetAsync(player.UserId, moneyStats.Value)
        end)
        end)
        coroutine.resume(saves)
    --//Autosaves
    while wait(5) do
        ds1:SetAsync(player.UserId, moneyStats.Value) 
    end
    end)    

When I press the button it doesn't print, "you pressed the button!"? Why doesn't this work?

0
that is probably cause you are using player added, player added works when the player joined the game so, remove that and get the player... greatneil80 2647 — 6y
0
how to get the player using sever script? jatytech 45 — 6y

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
6 years ago

Simple

StarterGuionly holds the GUIs that will be replicated to the clients, not the actual GUI found on their screen. It can be found at game.Players[PlayerName].PlayerGui. If you have FE on, this will be nil and you need to use remote events to send a click to the server.

Ad

Answer this question