Model's CFrame won't be set to mouse position

Hello! What I am trying to do is, if you click on any location with your mouse (whilst holding a tool), it will spawn a model, what I tried doing is setting the models CFrame with the mouse position using “CFrame.new”, but for some reason, it is not setting the CFrame.

local tool = script.Parent

tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		local mine = game.ServerStorage:FindFirstChild("LandMine")
		local cloned = mine:Clone().Parent == game.Workspace
		cloned.CFrame = CFrame.new(mouse.Hit.Position.X,mouse.Hit.Position.Y,mouse.Hit.Position.Z)
	end)
end)

Any Ideas?

local tool = script.Parent

tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		local mine = game.ServerStorage:FindFirstChild("LandMine")
		local cloned = mine:Clone();cloned.Parent == game.Workspace
		cloned.CFrame = CFrame.new(mouse.Hit.Position.X,mouse.Hit.Position.Y,mouse.Hit.Position.Z)
	end)
end)

Unfortunately, it does not work, no errors has printed in the console. I tried wrapping it in a pcall, still, no errors in console…

  1. Make a LocalScript in your tool:
--Local Script
local Tool = script.Parent
local RE = Tool:WaitForChild("RemoteEvent")


Tool.Equipped:Connect(function(mouse)
	Tool.Activated:Connect(function()
		RE:FireServer(mouse.Hit.Position)	
	end)
end)
  1. Make a RemoteEvent in your tool

  2. Make a script in your tool

--Script
local Tool = script.Parent
local RE = Tool.RemoteEvent

RE.OnServerEvent:Connect(function(Player, Position)
	local Clone = game.ServerStorage.LandMine:Clone()
	Clone.Parent = workspace
	Clone.CFrame = CFrame.new(Position)
end)

Tried that, didn’t work.
30char

I tried that, it spawns but not in the mouse location, I had it anchored and un anchored.
It now came with this error:
Screenshot_9

Change your script to:

--Script
local Tool = script.Parent
local RE = Tool.RemoteEvent

RE.OnServerEvent:Connect(function(Player, Position)
	local Clone = game.ServerStorage.LandMine:Clone()
	Clone.Parent = workspace
	Clone:MoveTo(Position)
end)
1 Like

It works! Thank you.
30char