Trying to make a shop script but it crashes my game when i buy it plz help
--Judgmentum
local illumina = script.Parent:WaitForChild("Illumina")
local units = game.Players.LocalPlayer:WaitForChild("leaderstats").Units
function buySword(swordName, price, button)
if units.Value >= price then
units.Value = units.Value - price
local weapon = game.ReplicatedStorage.Weapons:FindFirstChild(swordName)
if weapon then
local new = weapon:Clone()
new.Parent = game.Players.LocalPlayer.Backpack
new.Parent = game.Players.LocalPlayer.StarterGear
print("Purchase successful! Bought " .. swordName .. " for " .. price .. " units.")
else
print("ERROR: SWORD NOT FOUND, LINE 9 OF SCRIPT 'ShopBuy' IN MAIN > SHOPBUTTON > SHOPFRAME > SHOPBUY")
return false
end
button.Text = "Purchased."
wait(2)
button.Text = swordName
end
end
illumina.MouseButton1Click:connect(function() buySword("Illumina", 1000, illumina) end)

1 comment
What do you mean by "crash"? Does the script just error? Does Studio actually stop responding?