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)
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 ")"