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

How do you check for a certain item in ServerStorage?

I am trying to make a Spawner with a SurfaceGui in a certain way. I want to check if there's a certain model in the ServerStorage. An if not, I want to show a Frame for 8 seconds and return to start the start. But I'm not sure how to incorporate it into my code.

local c2 = game.ServerStorage.c2

script.Parent.MouseButton1Down:connect(function()
	game.ServerStorage.c2.Parent = workspace
end)

2 comments

0

LOL, Your variables can't have numbers

0

^ They can.

2 answers

local c2 = game:GetService("ServerStorage"):FindFirstChild("c2")

script.Parent.MouseButton1Down:connect(function()
	if c2 then
		--not sure what your intended use is, but you may want to do c2:Clone().Parent = workspace instead
		c2.Parent = workspace
	else
		--show the frame, wait 8 seconds, hide the frame
	end
end)

1 comment

0

I do not want to continue cloning, I want a certain amount of c2's to be able to spawn in and when there is none left, then there is none left

To have the code check for a certain item in any place, you must use FindFirstChild(""). You also don't need to direct to c2 again since you already defined the item earlier and you should define workspace beforehand.

local c2 = game.ServerStorage:FindFirstChild("c2") --FindFirstChild checks to see if an item exists
local workspace = game.workspace --workspace isn't predefined
local frame = game.StarterGuiname.Framename --define the frame here

script.Parent.MouseButton1Down:connect(function()
	if c2 then
		c2.Parent = workspace --You already set the directory for c2 so you just need to call upon what you named the variable.
	else
		frame.Visible = true
		wait(8)
		frame.Visible = false
end)

4 comments

0
  1. FindFirstChild returns nil if the object doesn't exist, 2) workspace is defined, 3) parenting nil (as such in point 1) throws an error
0

okay so you edit your code to mine but worse, why? btw-- "local frame = game.StarterGuiname.Framename", toggling the visibility of a frame in the startergui won't help anyone lol

0

Thanks for helping, I do have ways of fixing the visibility issue.

0

Won't work if i click a second time and there's nothing in the ServerStorage, and i don't want to clone it ether

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