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

What should I put after my function?

Asked by 4 years ago

I want to make an upgrade level for my weight but this script doesn't work, help me please! The output said this : " Players.TheKakYTArmy.PlayerGui.ShopGui.Box.Upgrade.Script:2: attempt to index local 'player' (a nil value)"

script.Parent.MouseButton1Click:Connect(function(player) if player.leaderstats.Cash.Value >= 100 then game.StarterPack.Weight.Level.Value = game.StarterPack.Weight.Level.Value + 1 player.leaderstats.Cash.Vlue = player.leaderstats.Cash.Value - 100 end end)

3 answers

Log in to vote
1
Answered by 4 years ago

I don't believe MouseButton1Click has any set parameters, you also made a couple mistakes within your script. Below is code that should work:

local player = game.Players.LocalPlayer -- assuming leaderstats is held within the player's folder

script.Parent.MouseButton1Click:Connect(function()
if player:WaitForChild("leaderstats").Cash.Value >= 100 then
    game.StarterPack.Weight.Level.Value = game.StarterPack.Weight.Level.Value + 1
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100
    end
end)
0
The output says that the line 4 is incorrect TheKakYTArmy 125 — 4y
0
This is the best answer here so ok TheKakYTArmy 125 — 3y
Ad
Log in to vote
0
Answered by 4 years ago

I found the script myself, the script is actually ~~~~~~~~~~~~~~~~~ player = script.Parent.Parent.Parent.Parent.Parent money = player.leaderstats.Cash price = game.StarterPack.Weight.Level.Value * 100

function buy() if money.Value >= price then money.Value = money.Value - price game.StarterPack.Weight.Level.Value = game.StarterPack.Weight.Level.Value + 1

end end script.Parent.MouseButton1Down:connect(buy)

~~~~~~~~~~~~~~~~~ Thank you for trying, but nothing worked so I just made the script myself.

Log in to vote
-1
Answered by
NSMascot 113
4 years ago
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
 if player.leaderstats.Cash.Value >= 100 then
game.StarterPack.Weight.Level.Value = game.StarterPack.Weight.Level.Value + 1
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100
    end 
end)
0
don't spoonfeed code DeceptiveCaster 3761 — 4y
0
? NSMascot 113 — 4y

Answer this question