Problem generating a model from a button

(The title may be “vague” but I don’t know what to call it)
So I tried to make a system in which if you click on the button it will clone the “model” that is in ServerStroage and put the “model” in the workspace and in the user’s HumanoidRootPart position but the problem is that I never used model positions and I have problems.
image

Output:image

LocalScript:
script.Parent.Parent.Spawn.MouseButton1Click:Connect(function()

local characterRoot = game.Players.LocalPlayer.Character.HumanoidRootPart

game.ReplicatedStorage.RemoteEvent:FireServer(characterRoot)

end)

ServerScript:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(characterRoot)

local f = game.ServerStorage.Model:Clone()

f.Parent = workspace

f:MoveToSetPrimaryPartCFrame(characterRoot.CFrame)

end)

What did I do wrong to keep the system from working?

1 Like

RemoteEvents send the player who sent the request first when it’s Client → Server

RemoteEvent.OnServerEvent:Connect(function(player, arg1) -- the player who sent the request is sent first, not the argument you sent
-- arg1 would be the argument that you sent

-- do stuff

end)

Your server script should be:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, characterRoot)
   local f = game.ServerStorage.Model:Clone()

   f.Parent = workspace
   f:SetPrimaryPartCFrame(characterRoot.CFrame) -- use "SetPrimaryPartCFrame" not "MoveToSetPrimaryPartCFrame"
end)
3 Likes

Regarding the first(hugecoolboy2007):then it has to stay like this?


Regarding the second(rbbattlescreator2): adding parent makes it nil

1 Like

sorry wrong image
:

For the LocalScript, don’t put the local player as the first argument, roblox does that automatically

the event would look like this:

RemoteEvent.OnServerEvent:Connect(function(player, player, arg1)

end)

Just send the argument that you want, not the player (aka, your original local script)

1 Like

Ok it seems that I no longer remember remove events well, I’ll have to remember how to use