I'm making an egg hunt game so I want whenever you collect an egg, it activates a bool value that determines whenever you rejoin the game, it wont let you collect the egg for the 2nd time. I tried using DataStores to save the value but it doesn't seem to work. This is my whole datastore script, which is located in ServerScriptStorage.
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("EggSaveSystem") game.Players.PlayerAdded:connect(function(player) local leader = Instance.new("Folder",player) leader.Name = "leaderstats" local Eggs = Instance.new("IntValue",leader) Eggs.Name = "Eggs" Eggs.Value = ds:GetAsync(player.UserId) or 0 ds:SetAsync(player.UserId, Eggs.Value) Eggs.Changed:connect(function() ds:SetAsync(player.UserId, Eggs.Value) ds:SetAsync(player.UserId, game.Workspace.Eggs.egg1.Collected.Value) end) end) game.Players.PlayerRemoving:connect(function(player) ds:SetAsync(player.UserId, player.leaderstats.Eggs.Value) ds:SetAsync(player.UserId, game.Workspace.Eggs.egg1.Collected.Value) end)
This is the code that is runs whenever the egg is collected.
local egg = "egg1" game.ReplicatedStorage.EggRemote:FireServer(egg) game.Workspace.Eggs[egg].Collected.Value = true game.Workspace.Eggs[egg]:Remove() script:Destroy()
Finally, here is the code for the egg remote handler that it's firing.
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("EggRemote") remote.OnServerEvent:connect(function(player, eggType) if game.Workspace.Eggs[eggType].Collected.Value == false then player.leaderstats.Eggs.Value = player.leaderstats.Eggs.Value +1 else end end)
Hopefully this is enough information for you to attempt to help me. Thanks in advance.
If it isn't saving and isn't a code error, it may be what you added you need to use a numbervalue not any other ones. If this didn't work please tell me in the comments and I will do a bit more looking at the code.