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

Need to make it so the "Money" in 'leaderstats' in the game deducts 1100 when clicked (>=1100)?

Asked by
FedrixYT -21
7 years ago
local tool = game.Lighting.M249
script.Parent.ClickDetector.mouseClick:connect (function(plr)
    local yes = tool:Clone()
    yes.Parent = plr.Backpack

end)
0
Have you made an attempt at this? TheHospitalDev 1134 — 7y
0
yes have FedrixYT -21 — 7y
0
Well, did it work? SwiperCraft -2 — 7y
0
Is it working now?If not ill start working on the script myself and find out whats wrong. iisavagemuffins 0 — 7y

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You're gonna have to fix the case when indexing the MouseClick property, and add an if statement that checks the player's money. After that the script should function properly.

Note: Lighting isn't meant for storage, use ReplicatedStorage.

local tool = game.ReplicatedStorage.M249
local amount = 1100

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    local stat = plr.leaderstats:FindFirstChild("Money")
    if stat.Value >= amount then --Check if the player has enough
        local yes = tool:Clone()
        yes.Parent = plr.Backpack
        stat.Value = stat.Value - amount --Subtract money
    end
end)
0
thanks it worked! but the only reason i put it in lighting is because i had some other things in replicated storage i didn't want to get mixed up with FedrixYT -21 — 7y
0
Ah ok cool. Glad I could help :D Goulstem 8144 — 7y
0
ok FedrixYT -21 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

You are close

local player = game.Players.LocalPlayer
local tool = game.Lighting.M249

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local yes = tool:Clone()
    yes.Parent = plr.Backpack
    if (player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") and (player.leaderstats.Money.Value > 0)) then
        player.leaderstats.Money.Value = (player.leaderstats.Money.Value - 1100);

    end
end)


0
Workspace.buy m249.Script:7: attempt to index upvalue 'player' (a nil value) is what the out put said FedrixYT -21 — 7y
0
Must be how you are putting the script in.... Works perfectly fine for my game. GuestRealization 102 — 7y

Answer this question