Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Money system not functional?

Asked by 4 years ago

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!

0
well for one thing the variable 'vbucc' doesnt equal anything sean_thecoolman 189 — 4y
0
Yup iivSnooxy 248 — 4y
0
it sets it on line 7 wdym MrDeland 0 — 4y
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 NoahsRebels 99 — 4y
0
it isn't a localscript, should i still use it? MrDeland 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)
0
still getting my money back, isn't that the same as +=? MrDeland 0 — 4y
0
yeah, v = v + 1 is the same as v+= 1 NoahsRebels 99 — 4y
0
what is difference? MrDeland 0 — 4y
Ad

Answer this question