I don’t know why but suddenly all my leaderstats in my games all suddenly crashed. Is this just me or is it global?
Probably an error in the script. Can we see the script? Also when you say crash, you mean they stopped working?
Yup exactly. 0 Errors and no sign of anything wrong expect the fact that the leaderstat ISNT WORKING. This is super weird casue i didnt change any of my scripts at ALL and they are glitching.
That is very weird. Can I see your script, maybe you accidentally changed it? It’s also possible that another script is accidentally deleting the leaderstats. While in game could you check the explorer and see if there is a folder named leaderstats in the player.
Sure and no the isnt a leaerstat. Here is my script
local DataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local playerData = DataStoreService:GetDataStore("PlayerDataBounty")
local function onPlayerJoin(player) -- Runs when players join
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Bounty"
cash.Parent = leaderstats
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
-- Data exists for this player
cash.Value = data
else
-- Data store is working, but no current data for this player
cash.Value = 0
end
end
local function onPlayerExit(player) --Runs when players exit
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.leaderstats.Bounty.Value) --Saves player data
end)
if not success then
warn('Could not save IvyBux data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
game:BindToClose(function()
for _, plr in ipairs(players:GetPlayers()) do
coroutine.wrap(onPlayerExit)(plr)
print("All data saved!")
end
end)
Wait…so if you go into the game there is no folder named leaderstats in the player?
Nope. Nothin. Its so weird!! Idk what to do.
Very weird. Right below these lines could you add some prints so that we can see if the leaderstats is immediately destroyed or what.
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
Add the following:
while wait() do
print("The leaderstats is in "..leaderstats.Parent.Name)
end
I know this is unlikely, but is there any chance that your script is disabled.
Also help here: How To Save a Folder to DataStoreService - #9 by CoderHusk
ight bet sounds good ill def do that
Try doing this before player added,
for i, plr in pairs(game.Players:GetPlayers()) do
onPlayerJoined(plr)
end
Yeah… you should make it print something after it’s done loading the leaderstats folder and everything in it
Could you guys also help here: How To Save a Folder to DataStoreService - #9 by CoderHusk
I would really appreciate it!
There is no point doing that. This is in a server script so it will already have made leaderstats for every single player.
I JUST FIGURED OUT MY ISSUE! My stupid little brother was messing with my game and moved all my scripts into server storage but i fixed it.
No? Being a server script just means it ran on the server, if the script starts listening for new players after a player already joined, it won’t create leaderstats. This will do it for already existing players.
If you have for example a module which takes a bit to load, it could cause that.
Yeah, but I think this is in ServerScriptService so it will be detecting PlayerAdded before any players have joined the game. I could be wrong though.
ServerScriptService doesn’t mean much, it is faster than workspace but it’s always good to have a for loop;