Hello everyone,

So I have a script that spawns a model from the serverstorage:

Server script (since you can't access serverstorage through a local script unless you use RemoteEvents):

game.ReplicatedStorage:WaitForChild("SpawnEvent").OnServerEvent:Connect(function(Player, Model)
    newModel = Model:Clone()
    newModel.Parent = workspace    
    newModel:makeJoints() -- Stops the model falling apart when it is spawned.
end)

But I get the the following error: ServerScriptService.SpawnEvent:2: attempt to index local 'Model' (a nil value) The "Model" value comes from a local script:

local spawnspawn = script.Parent:WaitForChild("Spawner")
local actualModel = spawnspawn.Value
local SpawnEvent = game.ReplicatedStorage:WaitForChild("SpawnEvent")

script.Parent.MouseButton1Click:Connect(function()
    SpawnEvent:FireServer(actualModel)
end)

Why is it not detecting the model stated in the Spawner.Value variable?

Thanks in advance!

4 comments

1

This is because even if you use an ObjectValue the client still can't see inside ServerStorage. Something wrong with putting it in ReplicatedStorage?

0

I didn't even knew that since I'm so used to ServerStorage, haha. So putting the model in ReplicatedStorage will solve the problem? I'll try doing it in ReplicatedStorage tomorrow then (it's late here, CEST, xd)

0

Oh okay. Yeah putting it in replicated storage should make your code work fine.

0

Ah it works now, thank you!