is there a way to, make this script not take the money, but just gives the item once it realize, you have enough exp, im working on a level system, and i realize the game does not work right when the script takes the money, so i wanted to know how do you make this script not take the money but finds the amount and you click it and it give tool, but if you dont have enough money i wont give it too you.
wait(0.5) player = script.Parent.Parent.Parent.Parent.Parent money = player.leaderstats.Exp price = 150 tool = game.Lighting:findFirstChild("Beretta") -- put the excact weapon name here. the weapon has to be in game Lighting function buy() if money.Value >= price then money.Value = money.Value - price local a = tool:clone() a.Parent = player.Backpack local b = tool:clone() b.Parent = player.StarterGear end end script.Parent.MouseButton1Down:connect(buy)
If you do not want the user to lose money when purchasing the item, then do not subtract the money value like you do on line 10:
money.Value = money.Value - price -- this subtracts {price} from the money
Also try to indent your code, and use Connect
instead of connect
.
In that way you should delete money.Value = money.Value - price Also I rescripted it for easier use, and it looks like this SCRIPT:
-- Put this in a local script! -- VARIABLES local player = game:GetService("Players").LocalPlayer local leaderatats = player:WaitForChild("leaderstats") local Exp = leaderstats:WaitForChild("Exp") local ExpAmount = 150 -- Amount of Exp required to get weapon! local ReplicatedStorage = game:GetService("ReplicatedStorage") local toolName = "Berreta" -- Name of your Weapon, make sure to put Weapon into ReplicatedStorage! local tool = ReplicatedStorage:WaitForChild(toolName) function buy() if Exp.Value >= ExpAmount then -- Checks if player has the right amount of Exp! local a = tool:Clone() a.Parent = player.Backpack local b = tool:Clone() b.Parent = player.StarterGear end end script.Parent.MouseButton1Click:Connect(buy)
This script does what it does, it's not the best, but then again it's working. I didn't tested it, but I'am quite sure that it will work! CHANGES I DONED: You used Lighting
as your storage which is deprecated, I switched to ReplicatedStorage
, also your script contained clone
, findFirstChild
and connect
which I've changed cause they are deprecated. I also added :WaitForChild()
to make script more smoother and because thing cand load instantly so. Hope this helped you.