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)

1 comment
get rid of the ) on the end on line 24.