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)
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)
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