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

Money system not functional?

So, I am currently making a game with a money system to buy speed/jump power. When I buy something and then press the button that gives you money, it gives my money back plus how much it is supposed to give you. Why is this happening? (the money is called vbucc, I'm gonna make all the scripts into one, seperated into comments for your viewing.

-- Button

local button = script.Parent
local vbucc

button.ClickDetector.MouseClick:Connect(function(player)
	vbucc = player.leaderstats.vbucc
	vbucc.Value += 5
	button.BrickColor = BrickColor.new("Really red")
	wait(.2)
	button.BrickColor = BrickColor.new("Lime green")
end)

-- Shop Speed Button (GUI)

local player = game.Players.LocalPlayer
local button = player.PlayerGui.Shop2.MainFrame.Speed.speed2

button.MouseButton1Down:Connect(function()
	local cash = player.leaderstats.vbucc
	if cash.Value >= 500 then
		cash.Value -= 500
		player.Character:FindFirstChild("Humanoid").WalkSpeed = 32
	end
end)

-- Shop Jump Button (GUI)

local player = game.Players.LocalPlayer
local button = player.PlayerGui.Shop.MainFrame.Jump.jump2

button.MouseButton1Down:Connect(function()
	local cash = player.leaderstats.vbucc
	if cash.Value >= 500 then
		cash.Value -= 500
		player.Character:FindFirstChild("Humanoid").JumpPower = 100
	end
end)

Please help!

5 comments

0

well for one thing the variable 'vbucc' doesnt equal anything

0

Yup

0

it sets it on line 7 wdym

0

I don't know if this would solve the problem, but you need to use a RemoteEvent if you wanna set someones leaderstat value from a local script

0

it isn't a localscript, should i still use it?

1 answer

If you are trying to add an amount of cash or add value to a value, then try this.

-- Button

local button = script.Parent
local vbucc

button.ClickDetector.MouseClick:Connect(function(player)
    vbucc = player.leaderstats.vbucc
    vbucc.Value = vbucc.Value + 5
    button.BrickColor = BrickColor.new("Really red")
    wait(.2)
    button.BrickColor = BrickColor.new("Lime green")
end)

-- Shop Speed Button (GUI)

local player = game.Players.LocalPlayer
local button = player.PlayerGui.Shop2.MainFrame.Speed.speed2

button.MouseButton1Down:Connect(function()
    local cash = player.leaderstats.vbucc
    if cash.Value >= 500 then
        cash.Value = cash.Value  + 500
        player.Character:FindFirstChild("Humanoid").WalkSpeed = 32
    end
end)

-- Shop Jump Button (GUI)

local player = game.Players.LocalPlayer
local button = player.PlayerGui.Shop.MainFrame.Jump.jump2

button.MouseButton1Down:Connect(function()
    local cash = player.leaderstats.vbucc
    if cash.Value >= 500 then
        cash.Value = cash.Value  + 500
        player.Character:FindFirstChild("Humanoid").JumpPower = 100
    end
end)

3 comments

0

still getting my money back, isn't that the same as +=?

0

yeah, v = v + 1 is the same as v+= 1

0

what is difference?

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