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

Button Gui won't accept money and would always decline?

Asked by 7 years ago

Hello everyone! What I attempted to create was a script where if a button is pressed, it would take away the money and clone the item to the players backpack. The problem is, when I tested it out in studio, it would always decline, even if it's over the designated price.

I created a module in serverscriptservice, where it creates a folder in the player, which I defined as funds in the following code.

Shop Local Script :

local amount = 2400
local player = game.Players.LocalPlayer
local Funds = game.Players.LocalPlayer.Stats.Money.Value

script.Parent.MouseButton1Click:connect(function()
      print("Button1 Clicked")

if Funds >= amount and not player.Backpack:FindFirstChild("ClassicSword") then
game.ReplicatedStorage["ClassicSword"]:Clone().Parent = game.Players.LocalPlayer.Backpack
print("Sword bought")
else 
print("Insufficient Funds")

end
end)

Any help is appreciated. Also, could you please explain the way you would fix it, because I just started scripting so I may not understand your methods.

1 answer

Log in to vote
0
Answered by 7 years ago

Your problem is that you are making the variable as the value and that you are only setting the variable once (at the beginning, before the function). you can easily fix this by moving .Value in the function.

local amount = 2400
local player = game.Players.LocalPlayer -- you weren't using this variable before
local Funds = player:WaitForChild("Stats"):WaitForChild("Money")
script.Parent.MouseButton1Click:connect(function()
    print("Button1 Clicked")
    if Funds.Value >= amount and (not player.Backpack:FindFirstChild("ClassicSword")) then
        game.ReplicatedStorage["ClassicSword"]:Clone().Parent =                                 game.Players.LocalPlayer.Backpack
        print("Sword bought")
    else 
        print("Insufficient Funds")
    end
end)

0
:3 that's exactly what he did except in funds he added .Value greatneil80 2647 — 7y
0
do you even script creeperhunter76 554 — 7y
0
*Cough* You didn't even get rep from this dumb script of yours greatneil80 2647 — 7y
0
dumb script? It should work, idiot. creeperhunter76 554 — 7y
Ad

Answer this question