I was watching AlvinBlox tutorial and usually used the Youtube comment section to find errors and such, with this video it seemed like there wasn't many people posting their issues, the video in question is here: https://www.youtube.com/watch?v=5AUP9C0rtBY&t or you can just youtube/google "How to make a Roblox Game Saving Data (4)"
I have tried some trouble shooting myself, but this is my first time working with Datastores themselves so I got confused and with Roblox giving no errors and me not understanding how to find errors by using Roblox's method: https://developer.roblox.com/en-us/articles/Datastore-Errors ( Just simply didn't understand how to do this )
yes, the game is published with API services and HTTP request.
Mainly when I edited the code around a bit it would seem to read I would always be a new player and not a returning one, so maybe the issue is around here? ( Yes I have put print statements under both of these and ran the game myself. )
Thank you for any help, I have been up for hours staring at this text lol
if player_data ~= nil then
-- Load the players saved data
bucks.Value = player_data
else
-- Player has no data to Load
bucks.Value = defaultCash
end
Full Code Here:
local dataStores = game:GetService("DataStoreService"):GetDataStore("BucksDataStore")
local defaultCash = 10
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bucks = Instance.new("IntValue")
bucks.Name = "Bucks"
bucks.Value = 0
bucks.Parent = leaderstats
player.CharacterAdded:Connect(function(character)
character.Humanoid.WalkSpeed = 16
character.Humanoid.Died:Connect(function()
-- On Character deaths, this will run
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player.LoadCharacter()
end)
end)
-- Data Stores
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."Bucks")
end)
if player_data ~= nil then
-- Load the players saved data
bucks.Value = player_data
else
-- Player has no data to Load
bucks.Value = defaultCash
end
end)
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
dataStores:SetAsync(player.UserId.."-Bucks",player.leaderstats.Bucks.Value)
print("Saved")
playersLeft = playersLeft - 1
bindableEvent:Fire()
end)
end)
game:BindToClose(function()
-- Triggered upon shutdown
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)

1 comment
Ahh I see, ty for that. I suppose for my own code projects Ill probably just avoid Hyphens, it seems like weird extra words for no reason.