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

How to fix a buy button script to put a speed coil in a player's backpack?

Asked by 4 years ago

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")
2end

1 answer

Log in to vote
0
Answered by
Warphi 51
4 years ago

there were a couple of problems in there, see below. this should work(?) although i am new to scripting as well so no promises

01local button = script.Parent
02local player = game:GetService("Players").LocalPlayer --add the .localplayer, before you were just grabbing the service, not the actual player
03 
04button.MouseButton1Click: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
10end)
Ad

Answer this question