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

How to detect a Model in ServerStorage with a Server Script Service script?

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:

local Event = game.ReplicatedStorage.GiveDropper
Event.OnServerEvent:Connect(function(data)
	if game.ServerStorage:FindFirstChild(data.Name) then
		print("Found")
		local Cloned = game.ServerStorage:FindFirstChild(data.Name):Clone()
		Cloned.Parent = game.Workspace
	end
end)

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

 local  Button = game.Workspace.Button
	local Gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("NoCash")
	local Event = game.ReplicatedStorage.GiveDropper
game.Workspace.Button.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Cash = game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Cash")
		if Cash.Value >= 50 then
			Button:Destroy()
			Cash.Value = Cash.Value - 50
			game.Workspace.BoughtSound:Play()
			Event:FireServer("FishingMachine")
			print("Fired")
			else
			Gui.Visible = true
			wait(1.2)
			Gui.Visible = false
		end
	end
end)
		

Ive tried this:

local Event = game.ReplicatedStorage.GiveDropper
Event.OnServerEvent:Connect(function(player,data)
    if game.ServerStorage:FindFirstChild(data.Name) then
        print("Found")
        local Cloned = game.ServerStorage:FindFirstChild(data.Name):Clone()
        Cloned.Parent = game.Workspace
    end
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

Still doesnt work.

1 answer

When receiving an event from the client the first parameter will always be the player, so your server function would be:

local Event = game.ReplicatedStorage.GiveDropper
Event.OnServerEvent:Connect(function(player,data)
    if game.ServerStorage:FindFirstChild(data.Name) then
        print("Found")
        local Cloned = game.ServerStorage:FindFirstChild(data.Name):Clone()
        Cloned.Parent = game.Workspace
    end
end)

4 comments

0

Oh, ill see if that does anything.

0

Ive tried , but i get 'Argument 1 missing or nil' in the Output.

0

NEVERMIND STUPID MISTAKE FORGOT TO CHANGE A LINE

0

No still doesnt work.

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