Spawn a model in the mouse position

Hello, I know I made a post similar to this one, but I’m having the same problem, doing it with a tool, with the scripts you gave me, they don’t work from a tool, the part is generated in the player’s position and not in the position of the mouse.

(Scripts from the other post)

--local script--
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	game.ReplicatedStorage.Spawner:FireServer(mouse.Hit)
end)
--Server script--
local Replicated = game:GetService("ReplicatedStorage")
local Storage = game:GetService("ServerStorage")
local Remote = Replicated:FindFirstChild("CreateWall")

Remote.OnServerEvent:Connect(function(Player, Pos)
	local Wall = Storage:FindFirstChild("Wall"):Clone()
	Wall.CFrame = Pos
	Wall.Parent = workspace
	task.wait(3)
	Wall.Anchored = false
	Wall.CanCollide = false
end)

image

Hey @RoboTest_Official,
Did you declare mouse as a variable in your local script? Reason why I ask this is because I
I see you go down the path to get the Mouse and connect to its event. If that local script is all you have under it, I suspect that you’re actually passing nil and the server is defaulting the part’s CFrame to CFrame.new(0,0,0) because you have not assigned mouse to anything.

-- My Version
local RemoteEvent 	= game.ReplicatedStorage:WaitForChild("RemoteEvent"); -- obviously our remoteEvent
local Mouse = game.Players.LocalPlayer:GetMouse(); -- I declared the variable so I can use it throughout the script

Mouse.Button1Down:Connect(function() -- Listening to Button1Down Event
	local mouseCFrame:CFrame = Mouse.Hit; -- Since we made Mouse a variable we can continue to access it without having to run :GetMouse() every time.
	RemoteEvent:FireServer(mouseCFrame);
end)

I get a error:
image
image

Error:
image

The error is caused by the :FireServer with the local player because player is automatically supplied.

This leads to the OnServerEvent being (player, player, leaderstats, mouseCFrame).

So try doing it with

:FireServer(leaderstats, mouseCFrame)

I only need mouseCFrame, so i can
:FireServer(lmouseCFrame)

I used it and i got this:
image
I printed mousecframe, and its prints “RoboTest_Official”

To debug OnServerEvents I recommend you to print out the function inputs using this trick:

OnServer:Connect(function (...)
print(...) --It should be player1, mouseCFrame
end)

I did it and it print “RoboTest_Official”

@dthecoolest Here is the print

Odd, that means mouse.Hit is missing, not sure which local script you used is as it keeps changing and is within a screenshot.

Here is the full code I used which works

--local script--
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(mouse.Hit)
end)
--Server script--
local Replicated = game:GetService("ReplicatedStorage")
local Storage = game:GetService("ServerStorage")
local Remote = Replicated.RemoteEvent

Remote.OnServerEvent:Connect(function(Player, Pos)
	local Wall = Storage:FindFirstChild("Wall"):Clone()
	Wall.CFrame = Pos
	Wall.Parent = workspace
	task.wait(3)
	Wall.Anchored = false
	Wall.CanCollide = false
end)

image

Replace the OnServerEventFunction with

Event.OnserverEvent:Connect(function(player, mouseCFrame)
local bomb = game.ServerStorage.Items.Bombs.BombModel
local a = bomb:Clone()
a.Parent = workspace
a.CFrame = mouseCFrame
end)

image

I suggest you use raycasting because the :GetMouse() is faulty and doesn’t work really well when u place. I’ve made a thread where u can add your own building objects you can look at it here. And if u use my open-source building system then there can be simple changes to make it compatible with models. If u do use It u can use :MoveTo() rather than .Position. If u need any more help just reply.