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

Number values stay the same after changing them?

I'm making a shop and I wanted to make it so that when you have 300 cash, you can buy a moveset.

The problem is that when I buy something, it takes away cash but then as soon as it adds cash, it gives all the cash it took away back.

Here is a video showing what it does: https://www.youtube.com/watch?v=jIRrJ8iAE7g&feature=youtu.be&ab_channel=DankDesmondo

And heres my code:


Giving the currency script

game.Players.PlayerAdded:Connect(function(player) local Value = Instance.new("NumberValue", player) Value.Name = "Currency"

while wait(10) do
	
Value.Value = Value.Value + 300

end

end)


Buying Things script

script.Parent.MouseButton1Down:Connect(function()

if Player:WaitForChild("Currency").Value >= 299 then
	game.ReplicatedStorage:FindFirstChild("BH"):Clone()
	game.ReplicatedStorage.BH.Parent = Player.Backpack
	
	Player:WaitForChild("Currency").Value = Player:WaitForChild("Currency").Value - 300

end end)

1 answer

Alright, I had a similar issue regarding this topic. Here is the problem. You are taking away the cash from the client. But adding it through a script. You need to use 'Remote Events'. You need to subtract the value from the player from a 'script'. Because when you deduct it from a client, the server won't be able to see any changes. It will only happen 'on the client'. You need to deduct the money from the server. You will need to learn about 'Remote Events' as they let you communicate between server and client. You will need to fire a remote event from a local script and deduct the price inside a script.

Here is a useful link for learning remote events:

https://www.youtube.com/watch?v=wCr5VXJ34T4

And here is another:

https://www.youtube.com/watch?v=GwhPXyYKkwU

Hope it helped.

2 comments

0

Thanks, it worked.

0

Please accept the answer if it helped.

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