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

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

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

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)

4 comments

0

:3 that's exactly what he did except in funds he added .Value

0

do you even script

0

Cough You didn't even get rep from this dumb script of yours

0

dumb script? It should work, idiot.

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