Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I need help with my currency system?

For example, if someone buys something from my shop, they loose that amount of money but get the item, so lets say an item happens to be 3000 points and they buy it. If they suddenly to gain a point, for example 1, it goes straight to 3001. So the previous number + the points they just gained. You know what I mean? Here

local CountName = "Points"

game.Players.PlayerAdded:connect(function(Player)
	local leaderstats = Player:FindFirstChild('leaderstats') or Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Points = leaderstats:FindFirstChild(CountName) or Instance.new("IntValue", leaderstats)
	Points.Name = CountName
	Points.Value = 0
	
	Player.CharacterAdded:connect(function(Character)
		local d = true
		Character:WaitForChild("Humanoid").Died:connect(function()
			if (d) then
				d = false
				Points.Value = Points.Value + 100
			end
		end)
	end)
end)

By the way, this is the script that people earn points from. All I need is the points to not reset after they buy something.

3 comments

0

Parent argument is deprecated.

0

why did you name leaderstats after finding it in player? if the leaderstats is not named before trying to find it, it won't find it.

0

????I guess set a value of how many points get taken away? I am confused....

1 answer

Hi!

MY GUESS

I assume that you're also using a LocalScript to reduce the points from the play when he/she buys something in the store? If so, that's where the problem lies, not the Script.

Basically, a LocalScript can change anything a Script can, but only on the Firing Client. This means that if the Client was to purchase a tool in your shop, the points are reduced from the player's screen, but not from the server.

The server ofcourse saves the actual player's gold, and adds money to it. Because a LocalScript cannot change the server's gold save, it resets back to the original amount whenever the server adds extra points.

FIX

There's a way to fix this without moving everything to a script, and that's called a RemoteEvent! RemoveEvents allow LocalScript to fire certain actions only a Script can perform, which in this case is changing the player's gold on the server to stop the resetting!

You'll have to create a RemoteEvent that reduces the gold whenever the client buys an item, and fire it from the LocalScript.

Read more about RemoteEvents here: https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

I have experienced this same issue myself, and this solved it!

1 comment

0

I was already using remote events though, which is strange.

This discussion is preserved as it was. New answers, comments, and votes are closed.