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

What should I put after my function?

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

✓ Accepted answer

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)

2 comments

0

The output says that the line 4 is incorrect

0

This is the best answer here so ok

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.

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)

2 comments

0

don't spoonfeed code

0

?

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