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

    game.ReplicatedStorage.Tools.SpeedCoil:Clone().Parent = player:WaitforChild("Backpack")
end

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

local button = script.Parent
local player = game:GetService("Players").LocalPlayer --add the .localplayer, before you were just grabbing the service, not the actual player

button.MouseButton1Click:Connect(function()
    if player.leaderstats.Gold.Value >= 100 then
        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
        local SpeedCoil = game.ReplicatedStorage.Tools.SpeedCoil:Clone() --defining the clone
        SpeedCoil.Parent = player:WaitForChild("Backpack") --parenting the clone
    end
end)
Ad

Answer this question