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

How do i stop this script from taking the money?

Asked by 5 years ago

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)

2 answers

Log in to vote
1
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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.

0
so what exacly do i add, when i add + it gives the player the item and gives them the money, when i add this >= it eats all the money up Carforlife1 59 — 5y
0
^ what incapaz said, and also I mean just remove the line. You don't need it. chomboghai 2044 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
You're still wrong. User#19524 175 — 5y
0
Don't be reminding askers to accept your answer. If you truly helped, it is nature for the asked to accept your answer, You're just being greedy. User#19524 175 — 5y
0
Incapaz tell me please, what is wrong with mine script? AswormeDorijan111 531 — 5y
0
Man, he used model from toolbox, so he is wanting just to make 1 script, not remote events which he should be using but then again, for guys like this, its best to rescript a script.... Im sorry for my bad english Im not from England and plus I am typing from the phone.... AswormeDorijan111 531 — 5y
View all comments (2 more)
0
Thankyou very much! Thats what i was talking about! Carforlife1 59 — 5y
0
Glad to help you! AswormeDorijan111 531 — 5y

Answer this question