Any way I can fix this error?

Working on update for my game with a system that connect to the datastore system I have and I keep getting these and it breaks everything
(Repost) (Other scripts if needed ask)
Errors
image
image
Errors and code (More if you need to have it shown)
Playerdata store


Egg handler datastore
image

5 Likes

It would be nice if you send your script in text not in screenshots

3 Likes

I’d recommend adding some logic checks to see if leaderstats and Wallet exist. Of course they should but they don’t mean that they do.

Basically just do a:

if leaderstats and leaderstats:FindFirstChild("Wallet") then
-- code
end

Something like that should do the trick.

2 Likes

Egg code for collection
–// Variables
local Eggs = workspace.Eggs
local Players = game:GetService(“Players”)
script:WaitForChild(“EggHandler”, 1)
–// Main

for _, egg in ipairs(Eggs:GetChildren()) do
local ProxPrompt = Instance.new(“ProximityPrompt”)
ProxPrompt.Parent = egg
ProxPrompt.ActionText = “Collect”
ProxPrompt.ObjectText = “Trophie”
ProxPrompt.Triggered:Connect(function(player)

	player.leaderstats.Wallet.Value += 5000 --Wallet-
	if not player.Eggs:FindFirstChild(egg.Name) then
		local EggCollected = Instance.new("BoolValue")
		EggCollected.Name = egg.Name
		EggCollected.Parent = player.Eggs
	end
end)

end

3 Likes

Playerdata code
local DSS = game:GetService(“DataStoreService”)
local statsDS = DSS:GetDataStore(“statsDS”)

game.Players.PlayerAdded:Connect(function(plr)
local lead = Instance.new(“Folder”)
lead.Name = “leaderstats”
lead.Parent = plr

local wallet = Instance.new("IntValue")
wallet.Name = "Wallet"
wallet.Parent = lead
wallet.Value = 55000

local diam = Instance.new("IntValue")
diam.Name = "Bank"
diam.Parent = lead
diam.Value = 0

local Awards = Instance.new("IntValue")
Awards.Name = "Awards"
Awards.Parent = lead
Awards.Value = 0



local data

local succ, err = pcall(function()
	data = statsDS:GetAsync(plr.UserId.."-stats")
end)

if succ then
	print("success")
	if data then                    --if there was some data then
		print("Got the data from the player datastore")
		wallet.Value = data[1]
		diam.Value = data[2]
		Awards.Value = data[3]    
	end
else
	print("There was an error while checking: "..plr.Name)
	warn(err)
end

end)

game.Players.PlayerRemoving:Connect(function(plr)
print(“Player is leaving the game!”)
local wallet = plr.leaderstats.Wallet.Value
local diam = plr.leaderstats.Bank.Value
local Awards = plr.leaderstats.Awards.Value
print(“Got all the values”)

local data = {wallet, diam, Awards}

local succ, err = pcall(function()
	statsDS:SetAsync(plr.UserId.."-stats", data)
end)

if succ then
	print("Succesfully saved the data!")
else
	print("There was an error while saving player leaderstats!")
	warn(err)
end

end)

2 Likes

egg save code
local EggData = game:GetService(“DataStoreService”):GetDataStore(“EggData”)
local OtherEggData = game:GetService(“DataStoreService”):GetDataStore(“OtherEggData”)

game.Players.PlayerAdded:Connect(function(plr)
local Eggs = Instance.new(“Folder”, plr)
Eggs.Name = “Eggs”
local DidEasterEggQuest = Instance.new(“BoolValue”, plr)
DidEasterEggQuest.Name = “DidEasterEggQuest”
DidEasterEggQuest.Value = false
local ClaimedPrize = Instance.new(“BoolValue”, plr)
ClaimedPrize.Name = “ClaimedPrize”
ClaimedPrize.Value = false
local lead = Instance.new(“Folder”, plr)
lead.Name = “leaderstats”

local Data = EggData:GetAsync(plr.UserId)
local Data2 = OtherEggData:GetAsync(plr.UserId)
if Data ~= nil then
	for i, v in ipairs(Data) do
		local clone = Instance.new("BoolValue")
		clone.Name = v
		clone.Parent = plr.Eggs
	end
end
if Data2 ~= nil then
	ClaimedPrize.Value = Data2.ClaimedPrize
end

end)

game.Players.PlayerRemoving:Connect(function(plr)
local plrEggs = {}
for i, v in pairs(plr.Eggs:GetChildren()) do
table.insert(plrEggs, v.Name)
end
local dataother = {
ClaimedPrize = plr.ClaimedPrize.Value
}
EggData:SetAsync(plr.UserId, plrEggs)
OtherEggData:SetAsync(plr.UserId, dataother)
end)

2 Likes

Hang on, both the PlayerData Code and the Eggsave code make a leaderstats value

Is this really the case? Because if there are two leaderstats folders that would explain a lot

1 Like

yea but I don’t know how to make them combined

1 Like

Sorry for sounding aggressive, but you know how to format your code properly, right? I can barely read this. (You’re meant to surround all of the code with one pair of ```)

1 Like

No lol I’m very bad at coding only known it for a bit not too long

1 Like

It’s not exactly coding skills we’re talking about here, all you’re doing is copy-pasting text inside a pair of these: ```
They even explain it to you when you write the first post in this thread.
Again, sorry for the aggression, I’m not the best at approaching people.

1 Like

well Idk then I am stuck I only really can adjust and code minor things and I do add notes

1 Like

how would I make them into one???