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)
Is this a server script or a local script? Cause only local scripts are supposed to reach ReplicatedStorage. Try using ServerStorage if this is a server script like on line 9:
local weapon = game.ServerStorage.Weapons:FindFirstChild(swordName)
ReplicatedStorage always crashes my game, try using lighting instead. Put your swords in a model in lighting or just put your swords in lighting and use;
game.Lighting.Weapons:FindFirstChild(swordName)