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

How to detect in a script if there is a named Model in Server Storage?

Hi, I am trying to find a Model in ServerStorage. I am doing :FireServer("FishingMachine") in a Local Script in StarterGui, and the server script detects the OnServerEvent and trys to find the "FishingMachine" in serverstorage. I am trying this by doing this:

view source

1	local Event = game.ReplicatedStorage.GiveDropper
2	Event.OnServerEvent:Connect(function(data)
3	    if game.ServerStorage:FindFirstChild(data.Name) then
4	        print("Found")
5	        local Cloned = game.ServerStorage:FindFirstChild(data.Name):Clone()
6	        Cloned.Parent = game.Workspace
7	    end
8	end)

In the script that fires the event, it looks like this:

view source

01	local  Button = game.Workspace.Button
02	    local Gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("NoCash")
03	    local Event = game.ReplicatedStorage.GiveDropper
04	game.Workspace.Button.Touched:connect(function(hit)
05	    if hit.Parent:FindFirstChild("Humanoid") then
06	        local Cash = game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Cash")
07	        if Cash.Value >= 50 then
08	            Button:Destroy()
09	            Cash.Value = Cash.Value - 50
10	            game.Workspace.BoughtSound:Play()
11	            Event:FireServer("FishingMachine")
12	            print("Fired")
13	            else
14	            Gui.Visible = true
15	            wait(1.2)
16	            Gui.Visible = false
17	        end
18	    end
19	end)

Ive tried this:

1	local Event = game.ReplicatedStorage.GiveDropper
2	Event.OnServerEvent:Connect(function(player,data)
3	    if game.ServerStorage:FindFirstChild(data.Name) then
4	        print("Found")
5	        local Cloned = game.ServerStorage:FindFirstChild(data.Name):Clone()
6	        Cloned.Parent = game.Workspace
7	    end
8	end)

but says 'Argument 1 missing or nil' in the Output. It doesnt seem to find it. What else should i try and do?? I have checked for spelling mistakes and found none, in the script and the Model in ServerStorage. Thanks.

1 comment

0

code block

1 answer

✓ Accepted answer

Use FindFirstChild. FindFirstChild is used to find the first child of something named something. Example:

local Brick = workspace:FindFirstChild("Brick") 
if Brick then -- If we find a child in workspace called Brick
print("Brick is not late this time bruh") -- Prints out this
end

Hope this helps!

1 comment

0

Thank you so much!

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