Leaderstats Script Not Working. Please Help!

Try removing the parent in the variable. I’m pretty sure it might change something. It’s like: local part = game.Workspace.Part:Clone().Parent = game.Workspace
You wouldn’t want to specify the parent in the variable.

im so sorry i dont know what you mean, im only a kid and im not the best at scripting.

i added leaderstats.Parent = Player in.

o wait yea it didnt work

1 Like

That’s fine. Here’s the script applying what I mean.

local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“MoneyStats”)

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder")
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player
local Coins= Instance.new(“IntValue”)
Coins.Name = “Coins”
Coins.Value = 0
Coins.Parent = leaderstats
local Orbs= Instance.new(“IntValue”)
Orbs.Name = “Orbs”
Orbs.Value = 0
Orbs.Parent = leaderstats

local Data = DataStore:GetAsync(Player.UserId)
if Data then
	Coins.Value = Data.Coins 
	Orbs.Value = Data.Orbs 
end

end)

game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, {
[“Coins”] = Player.leaderstats.Coins.Value;
[“Orbs”] = Player.leaderstats.Orbs.Value;
})
end)
[/quote]

1 Like

ok, ill try it… :slight_smile:

One thing I would like to point out, is that you have no safety checks, like what if the DataStore fails to load, or even save? With pcall, you can determine if there are any errors, and catch them, if there is any. Inserting a pcall into a loop, with certain tries (to prevent leaking) will add some safety to saving and loading;

local success, errorMessage = false, ""
for i = 1, 10, 1 do -- It gives up once it has tried 10 times. It has to give up to prevent memory leaks.
    success, errorMessage = pcall(function()
        -- Do the data saving / loading
    end
    if success then break end -- If it successfully saved / loaded then quit retrying.
    wait(10) -- Wait a while before retrying again.
end

You can learn more about pcall here.


But the fact that you’re getting 100 money and 100 orbs is strange…

2 Likes

ok, i did that, and im still having the same issue…

Have you set the settings?


PS: Allows roblox studio to access datastores, clients already have access.

yes i have, but what does that have to do with currencies becoming the same? it also happens in the main game out of studio

Could we see the script to collecting the orbs?

There could be a separate script that’s also connected to PlayerRemoving, which sets the value to something, something…

ok, both coins and orbs are the same scripts, just changed in currencies

waittime = 5 – Time Between each hit
amnt = 10 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild(“Humanoid”)
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local leaderstatsstats = thisplr:findFirstChild(“leaderstats”)
if (leaderstatsstats~=nil) then
local orbs = leaderstatsstats:findFirstChild(“Orbs”)
if (orbs~=nil) then
orbs.Value = orbs.Value + amnt
end
end
end

    script.Parent.Transparency = 1
    script.Disabled = true
    wait(waittime)
    script.Parent.Transparency = 0
    script.Disabled = false


end

end

script.Parent.Touched:connect(onTouched)

1 Like

there is, actually… its for like chat messages for when someone joins and leaves, could that be it?

Go and have a look…?

Is there anything that’s modifying the values in leaderstats at all?

okay

(30303003030303030303030)

ok so theres one script that says this…

local events = game.ReplicatedStorage.Events

game.Players.PlayerAdded:Connect(function(plr)

events.Added:FireAllClients(plr)

end)

game.Players.PlayerRemoving:Connect(function(plr)

events.Removing:FireAllClients(plr)

end)

does that effect it?

ok, i gotta go… can we finish this up tomorrow please?

Have you tried indexing the data table with strings, instead of just data.orbs? I’m not sure if it makes a difference.


data["Orbs"]