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

Why does this script crash my game?

Asked by 9 years ago

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)
0
What do you mean by "crash"? Does the script just error? Does Studio actually stop responding? BlueTaslem 18071 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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)
Ad
Log in to vote
-1
Answered by 9 years ago

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)
0
ReplicatedStorage has NEVER crashed my game. Molten_Legacy 40 — 9y
0
Just give it a try :p feeliirie 5 — 9y
0
I did, didn't work. Molten_Legacy 40 — 9y
0
Does it still crash, or can it not find the swords? feeliirie 5 — 9y
View all comments (2 more)
0
Fixed it, it was actually an error in another script. Thanks though. Molten_Legacy 40 — 9y
0
Ok :P Sorry for wasting your time XD feeliirie 5 — 9y

Answer this question