Help with remote event parameters

Hi,
Ive been trying to make it so that when a player clicks a text button, a model clones.
My Problem:
The model is located in replicates storage and I Fire a remote event from a local script when the button is clicked, I set the model as a parameter to give to the server, but it does not work. I used prints to checks my work and in the local script printing the model works fine and as expected, while printing the parameter in the server script comes out as nil.
My Code:

--Local Script
button.MouseButton1Click:Connect(function()
print(model) -- prints as expected in output
RemoteEvent:FireServer(model)
end)

--Server Script

local function NewModel(model)
model:Clone()
end)

RemoteEvent.OnServerEvent:Connect(function(model)
print(model) -- Comes out as nil in output
NewModel(model)
end)

I want to be able to do this because the player might click on a different text button which fires the same remote event, but with a different model so I won’t have to repeat code. Any fixes or other ideas on how to do this? Maybe when firing the remote event, I can use a module script and put in the models I want as parameters? Let me know any feedback.

Are you trying to get the model from the localscript?

The model is in replicated storage when a player
clicks a text button it fires a remote event to the server from the local script with the model as a parameter but it becomes nil when passed to the server script

You can’t access replicatedstorage from a local script because its in . On the local script, fire the remote only with no parameters when you click the button, then on the server script, create the clone and spawn it once the remote has been fired

But if they clicked a different button for a different model I would have to repeat code I’m trying to fire this remote event from each different button but the models can be different which is why I have it as an argument btw when printing the model from a local script the local script has it but it is nil in the regular script

I’m presuming this is picking up the model in local function NewModel(model) try setting up different parameters and see if it works.

On the server side,you always need to reference the first argument to the player.( who fired the remote)

I was wrong about the local script cant access replicatedstorage, sorry bout that, I mixed it up with serverstorage and serverscriptservice, but the way I do it is fire the server on the client then on the server, I do the coding there.
Heres my code:

local script


local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")


textButton.MouseButton1Click:Connect(function()
	remoteEvent:FireServer()
end)

server script


local part = game:GetService("ReplicatedStorage"):WaitForChild("Part")

function spawnPart()
	local clonedPart = part:Clone()
	clonedPart.Parent = workspace
	
end

remoteEvent.OnServerEvent:Connect(function(clonedPart)
	spawnPart()
end)
1 Like

I changed the parameters but in the server side the model is still nil

Obviously since the first parameter is the Player and the rest are the other arguments send by the Client. And also you need to parent the clone to workspace since the clone is in nil by default.
ServerScript:

remoteEvent.OnServerEvent:Connect(function(player, clonedPart)
	clonedPart:Clone().Parent = workspace
end)

1 Like