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

My script's end on line 24 isn't working, it says it is a fail but I'm not sure what to do?

Asked by 4 years ago
Edited 4 years ago

Im not sure why it isn't working but all I know that it isn't. Im trying to learn Lua so I'd really like some help!

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

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

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

    local data
    local sucess, errormessage = pcall (function()
        data = myDataStore:GetAsync(player.UsedId.."-cash")
    end)

    if sucess then
        cash.Value = data
    else
        print("There was an error whilst getting your data")
        game.StarterGui.ScreenGui.TextLabel.Visible = not "TextLabel" Visible
        end) -- WHERE IT IS FAILING!

game.Players.PlayerRemoving:Connect(function(player)

    local sucess, errormessage = pcall (function()
        myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.value)
end)

    if sucess then
        print("Player Data Sucessfully Saved!")
    else
        print ("there was an when saving data!")
        warn(errormessage)
    end

end)
0
get rid of the ) on the end on line 24. ForeverBrown 356 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

If this answer helped you please make sure you accept it!

Your first problem in the script is this part:

game.StarterGui.ScreenGui.TextLabel.Visible = not "TextLabel" Visible

Because of this the whole script breaks.

You can't just put "TextLabel" and expect the script the know that is without using a local term.

It should work if you use this.

game.StarterGui.ScreenGui.TextLabel.Visible = not game.StarterGui.ScreenGui.TextLabel.Visible

The second problem is that you need 2 ends:

if sucess then
            cash.Value = data
        else
            print("There was an error whilst getting your data")
            game.StarterGui.ScreenGui.TextLabel.Visible = not game.StarterGui.ScreenGui.TextLabel.Visible
            end -- First one here, without ")"
    end) -- Second one here, with ")"
0
When you put it in the script, it makes it so not and game are next to each other, is that correct? Also i also wan tot know what the difference is between an end without a ")" and an end with a ")" so I can learn and use it later in scripting please. Used_Develop 14 — 4y
0
Also, the ScreenGui is only supposed to show up when the loading fails, it is basically saying "Your save didn't load, please rejoin". I know I should put a then or else somewhere to lead to it opening the gui only if it fails loading. Just not sure where to place it. Used_Develop 14 — 4y
Ad

Answer this question