#Why doesn't this datastoring work?
78 messages · Page 1 of 1 (latest)
Omg.... You opened a function and never gave a fuck about it...
And what can I do with it then? Put something in the ()? Cuz other than that, I've coded somthing below... oh wait, I need to call that function, ight?
** You are now Level 9! **
If we are seeing the entire bottom script then you should do:
game:BintToClose(function()
for _,v in pairs(game.Players:GetChildren()) do
savedata(v)
end
end)
savedata is a function you should make (just copy and paste everything you got under game.Players.PlayerRemoving till the first end of the 2nd if)
mfw non-modular programming 😠
make a datastore save function, call it on every player on close, call it on players leaving, save yourself writing the same shit 3 times on different event listeners
like this?
Yea... But you still have some end-s there that should not be there
Is that so? Script analisys doesn't tell me anything
And when I try to delete some of those, error pops up (in the script analysis)
Then your script is nesting sooo much
And I can't tell if you need these end by seing the screenshot of your script
Maybe send the script as a .lua file?
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(player.UserId.."coins")
end)
if success then
coins.Value = currentExperience
print(currentExperience)
end
end)
local function savedata()
game.Players.PlayerRemoving:Connect(function(player)
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
local success, errorMessage = pcall(function()
experienceStore:SetAsync(player.UserId.."coins", coins.Value)
end)
local success2, errorMessage2 = pcall(function()
experienceStore:UpdateAsync(player.UserId.."coins", coins.Value)
end)
if not success2 then
error(errorMessage2)
end
if not success then
error(errorMessage)
end
game:BintToClose(function()
for _,v in pairs(game.Players:GetChildren()) do
savedata(v)
end
end)
end)
end
What code? This one u sent me? I already did
Omg...
The one you already have
Just copy and paste it back
IN YOUR SCRIPT
And then paste it here
like wtf... how should I understand where the function ends? Should I start counting the end?
I pasted it here, it is my code, from the serverScriptsservice
Copy the code from the message, paste it into my script, and then paste it here
Dude
So, you want me to copy YOUR code, paste it into my script, and paste the full script here?
Open the script where you have the code
Press CTRL+A then CTRL+C then CTRL+V
Now, you can copy again the script
CTRL+A then CTRL+C
And paste it there
CTRL+V using format
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(player.UserId.."coins")
end)
if success then
coins.Value = currentExperience
print(currentExperience)
end
end)
local function savedata()
game.Players.PlayerRemoving:Connect(function(player)
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
local success, errorMessage = pcall(function()
experienceStore:SetAsync(player.UserId.."coins", coins.Value)
end)
local success2, errorMessage2 = pcall(function()
experienceStore:UpdateAsync(player.UserId.."coins", coins.Value)
end)
if not success2 then
error(errorMessage2)
end
if not success then
error(errorMessage)
end
game:BintToClose(function()
for _,v in pairs(game.Players:GetChildren()) do
savedata(v)
end
end)
end)
end
Now use format
I opened the script, copy and pasted, and pasted here
oh ok
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(player.UserId.."coins")
end)
if success then
coins.Value = currentExperience
print(currentExperience)
end
end)
local function savedata()
game.Players.PlayerRemoving:Connect(function(player)
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
local success, errorMessage = pcall(function()
experienceStore:SetAsync(player.UserId.."coins", coins.Value)
end)
local success2, errorMessage2 = pcall(function()
experienceStore:UpdateAsync(player.UserId.."coins", coins.Value)
end)
if not success2 then
error(errorMessage2)
end
if not success then
error(errorMessage)
end
game:BintToClose(function()
for _,v in pairs(game.Players:GetChildren()) do
savedata(v)
end
end)
end)
end
isn't this the same?
My God...
Hold the fuck up... Imma open Roblox Studio and do it for you...
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(player.UserId.."coins")
end)
if success then
coins.Value = currentExperience
print(currentExperience)
end
end)
local function savedata()
game.Players.PlayerRemoving:Connect(function(player)
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
local success, errorMessage = pcall(function()
experienceStore:SetAsync(player.UserId.."coins", coins.Value)
end)
local success2, errorMessage2 = pcall(function()
experienceStore:UpdateAsync(player.UserId.."coins", coins.Value)
end)
if not success2 then
error(errorMessage2)
end
if not success then
error(errorMessage)
end
game:BintToClose(function()
for _,v in pairs(game.Players:GetChildren()) do
savedata(v)
end
end)
end)
end
Good, now is perfect
Also, this doest make sense....
Did you ever think why we created a function in the first place?
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(player.UserId.."coins")
end)
if success then
coins.Value = currentExperience
print(currentExperience)
end
end)
function savedata(player)
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")
local success, errorMessage = pcall(function()
experienceStore:SetAsync(player.UserId.."coins", coins.Value)
end)
local success2, errorMessage2 = pcall(function()
experienceStore:UpdateAsync(player.UserId.."coins", coins.Value)
end)
if not success2 then
error(errorMessage2)
end
if not success then
error(errorMessage)
end
end
game.Players.PlayerRemoving:Connect(function(player)
savedata(player)
end)
game:BintToClose(function()
for _,v in pairs(game.Players:GetChildren()) do
savedata(v)
end
end)
This should work
Yea, and where are you doing that?
Wait a sec, create a new function, and copy and paste everything under game.Players.Removing
oh wait
UNDER
not with the player removing
I copied and pasted WITH the playerRemoving function
while I was supposed to leave it between savedata and bindToClose
You shoud've know that this doest make any sense
I mean, I didn't even thought about checking it, cause u said it will work. I just didn't read it correctly, and copied and pasted the player removing func. I mean I would check if there was game:Destroy() or while true do loop, so it won't crash my game, but in cases like this, I first listen to what others say
And, where's the learning when I just copy and paste what others do, well if I am curious of how somthing works, or I don't understand it, I ask people
True, but I explained as much and understandable I could and you did that ... thing
Yeah, cause I've mis-readen what u said, missed the ,,under" player.playerRemoving
And btw, tysm for helping me
Oh, and I think that every error is bad (almost), but is this bad? Cause when reducing/adding coins, it saves
Error message is the highlighted one
Why are you using UpdateAsync? I don't think is needed there
Because you already use SetAsync when player leaves/game close
Cause I had problems with setAsync, and I saw that setAsync sets the value for the first time, and update well, updates it
can setAsync also update the value? without problems
I guess... I'm using only GetAsync to get data and SetAsync to save it
So you should just use SetAsync
Oh ok, so I Can just delete the success2 and everything below it, not counting if not success then?
Delete everyone that has to do with UpdateAsync
Np
So, imma be closing this post, cya
