I need help on my script

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.

So you want the credits to be taken away when they purchase something using it?

you can remove the speedcoil part on client and the credit removing too, just do it on server

Yea, like it takes it away but when they rejoin it somehow comes back

That’s not possible unless you make another DataStore system which stores previous data.

If this can’t be fixed and no one gives me any answer by Thursday, i will give u solution since u helped me sooo much

No they can just get the current data, remove a value then save it.