I need help on my script

Well I’m pretty sure that it will but I think it wouldn’t matter anyway because your previous data store script wasn’t saving it and also on this part of the script,

local function AutomaticSave()
    while wait(1) do
        for i, Player in pairs(game:GetService("Players"):GetPlayers()) do
            Save(Player)
        end
    end
end

while wait(1) do that’s the time it automatically saves the data, so the player’s data would be saved every second and I recommend that you keep it like that in case of any disconnections from the game, etcetera but always feel free to change the number from one to something else.

Also if the script worked please let me know and make sure to mark is as a solution, thanks. :slight_smile:

1 Like

Ok, I will definitely mark as solution if it works!

1 Like

Thanks a lot, I’m glad I could be of help. Hopefully this fixes your issue.

1 Like

It’s fine I can just add back some stats since most of them were my friends, well I’ll get going to sleep now, bye. I’ll let you know if It works when I get on studio in the morning :smiley:

1 Like

That sound’s good, you know there’s a way to also add a custom command on an admin system to give and remove credits or even reset them?

2 Likes

Yea I do, cya
(Ignore: minimum characters)

1 Like

Good night, sleep well. I really hope this will solve your issue :slight_smile:

1 Like

ok, i tried it, everything works, just like before except for my problem. When the player gets the tool, then leaves they’re stats stay the same way they were before the purchase. I dont think anything was wrong with my data store script, i just think something was wrong in the tool purchase script, as i mentioned earlier in the topic.

1 Like

This is the output i get


Is something wrong with this local script on my textbutton

player = game.Players.LocalPlayer
backpack = player.Backpack

script.Parent.MouseButton1Click:Connect(function()
	local SpeedCoil = game.ReplicatedStorage.Tools.SpeedCoil:Clone() 
	if player.leaderstats.Credits.Value >= 100 then
		player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 100
		SpeedCoil.Parent = backpack
	end
end)

Does this need datastore, I don’t think anything was wrong with my data store script before as I mentioned in the beginning of the topic, my problem was when a tool was brought, the stats gave them a refund when they left. So now I’m stuck right where I started.

I think it because you never setup a system for tool saving, I can set one up inside of that script.

Thank, you you’re a huge help!

1 Like

You’re welcome, you can read up on how to save the tools here so when they rejoin they have it again.

Also for the output part, where are you putting the script? It should be placed inside of a server script which would go in ServerScriptService.

Fire a remote to remove credits if you want it to replicate.

I dont need the tools to save, i just need the credits to stay away. (Meaning not to give a refund)

How would I do that? I dont how to fire the event.

Use :FireServer() on the remote.

I know that part, but in between the parenthesis what do I write. Or i just leave it empty

So something like this


player = game.Players.LocalPlayer
backpack = player.Backpack

script.Parent.MouseButton1Click:Connect(function()
	local SpeedCoil = game.ReplicatedStorage.Tools.SpeedCoil:Clone() 
	if player.leaderstats.Credits.Value >= 100 then
		player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 100 
		SpeedCoil.Parent = backpack
                game.ReplicatedStorage.RemoteEvent:FireServer()

	end
end)
end)

What I would suggest is on server, listen to the remote, remove the credits and parent the speedcoil to the player’s backpack.