the script keeps crushing at line 5 " if player.leaderstats.Gold.Value " and this is a local script in a textbutton in a frame in a Screen Gui in the Starter GUI
can you explain me the problem with my script.
local button = script.Parent local player = game:GetService("Players")
button.MouseButton1Click:Connect(function() if player.leaderstats.Gold.Value >= 100 then player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 100
1 | game.ReplicatedStorage.Tools.SpeedCoil:Clone().Parent = player:WaitforChild( "Backpack" ) |
2 | end |
there were a couple of problems in there, see below. this should work(?) although i am new to scripting as well so no promises
01 | local button = script.Parent |
02 | local player = game:GetService( "Players" ).LocalPlayer --add the .localplayer, before you were just grabbing the service, not the actual player |
03 |
04 | button.MouseButton 1 Click:Connect( function () |
05 | if player.leaderstats.Gold.Value > = 100 then |
06 | player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 100 --do you mean to put a minus sign here? with the addition sign every time you click the button you will be adding 100 gold to your bank |
07 | local SpeedCoil = game.ReplicatedStorage.Tools.SpeedCoil:Clone() --defining the clone |
08 | SpeedCoil.Parent = player:WaitForChild( "Backpack" ) --parenting the clone |
09 | end |
10 | end ) |