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

Why does this script crash my game?

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

0

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

2 answers

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)

6 comments

0

ReplicatedStorage has NEVER crashed my game.

0

Just give it a try :p

0

I did, didn't work.

0

Does it still crash, or can it not find the swords?

0

Fixed it, it was actually an error in another script. Thanks though.

0

Ok :P Sorry for wasting your time XD

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