Cant set parent on server side using remote event

Im trying to make it when the remoteEvent is fired, a model would be parented to the player character. However, It would only make the model parented to the player on the client side, not the server side. Can someone tell me why this happens

Local Script:

local Model = exmaple:Clone()
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.V then
		print("combat on")
		Model.Parent = char
		ReplicatedStorage.RemoteEvent:FireServer(Model.Parent)
	end
end)

Server Script


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, Model)
	local char = plr.Character or plr.CharacterAdded:Wait()
	Model = char
end)

Aren’t you doing this locally?

yea then i fire the remote Event
which should make the model parented on the server script

From what I’m seeing, you are overwriting the Model parameter as the character, not changing the Model’s parent.

ReplicatedStorage.RemoteEvent:FireServer(Model.Parent)

the Model is Model.Parent

1 Like

Exactly, indexing doesn’t work like what you think.
In your current work. Model in ServerScript would only act as a normal variable, this means Model’s parent in LocalScript won’t change.

You can fix this by index the Parent in ServerScript instead.

-- LOCAL SCRIPT
if input.KeyCode == Enum.KeyCode.V then
		print("combat on")
		Model.Parent = char
		ReplicatedStorage.RemoteEvent:FireServer(Model) -- remove the .Parent
	end
-- SERVER SCRIPT
game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr, Model)
	local char = plr.Character or plr.CharacterAdded:Wait()
	Model.Parent = char -- add it here instead
end)
1 Like

I tried it before and this error showed up

ServerScriptService.test:4: attempt to index nil with 'Parent'

Maybe delete the parenting in LocalScript since it should be unnecessary now.

same problem, the error still showed up

In the scripts you are firing the remote called “RemoteEvent”

and then the function in the server script is connected to ConnectM6D

your using two different remotes

Sorry, i was editing the script and removing the unnecessary bit to post on the forum. Let me changed it back

was the model created on the client or the server? If it is created in the local script then it will be nil for server

yes, you are creating it in your client script. This is why the error attempt to index nil with 'Parent' is popping up

1 Like

it was a :Clone() in the local script

false alarm, the error did not showed up, bbut the model is still not parented to the character

is the model being created in server script?

Its already exist in replicated storage, i removed the :Clone(), still doesnt work

Is your clone being created on the localscript? You might want to change it so to just pass the name of the model you want cloned through the remote event and check if it exists in replicated storage by the server. If so then the server will clone and parent