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

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

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

✓ Accepted answer

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)

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