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

How do you check for a certain item in ServerStorage?

Asked by 6 years ago

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)


0
LOL, Your variables can't have numbers forbrad 2 — 6y
0
^ They can. TheeDeathCaster 2368 — 6y

2 answers

Log in to vote
0
Answered by
c0des 207 Moderation Voter
6 years ago
Edited 6 years ago
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)
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 cedricjake2006 2 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
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 c0des 207 — 6y
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 c0des 207 — 6y
0
Thanks for helping, I do have ways of fixing the visibility issue. cedricjake2006 2 — 6y
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 cedricjake2006 2 — 6y

Answer this question