Placeable tool not working

So I want to make a placeable tool. This is the script I made:

local Tool = script.Parent
FC = script.Parent:WaitForChild("ClientToServer")

use = true

function script.Parent.ClientToServer.OnServerInvoke(player, mouse_pos)
	if use then
		use = false
		local StickyBomb = Tool.Handle:Clone()
		StickyBomb.Parent = workspace.DebriCleaner
		StickyBomb.Name = "StickyBomb"
		StickyBomb.CanCollide = true
		StickyBomb.Anchored = true

		StickyBomb.Size = Tool.Handle.Size
		StickyBomb.CFrame = Vector3.new(mouse_pos)
		use = true
		
	end
end

But It doesn’t work. I the clone of the tool handle to go anchored on the position where the mouse position is. But it doesn’t work: the only error I get is:

invalid argument #3 (CFrame expected, got Vector3)

1 Like

Change

StickyBomb.CFrame = Vector3.new(mouse_pos)

to

StickyBomb.CFrame = CFrame.new(Vector3.new(mouse_pos))

Note your setting a CFrame which is a positional, and position object. You can view the documentation here. CFrame | Roblox Creator Documentation You can pass a Vector3 in to set its position, but you have to use CFrame.new

1 Like

Use a CFrame instead, not a Vector3.

Nevermind. I noticed that if I place it on the baseplate that it doesnt place where i clicked. it places in the middle of the baseplate. how do i fix it?

No, that should have fixed your problem. Is it not moving or what? Also, are you sure the function is being fired more than once?

I mean it moves to the middle of the baseplate

What is mouse_pos? What function/method are you using to get that on the client?

this is the script that gets the mouse pos:

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()

tool = script.Parent
tool.Activated:Connect(function()
	local FC = tool:WaitForChild("ClientToServer")
	if FC then
		FC:InvokeServer(mouse.Hit)
	end
end)

I see… change your server code from
StickyBomb.CFrame = CFrame.new(Vector3.new(mouse_pos))

to

StickyBomb.CFrame = mouse_pos

Mouse | Roblox Creator Documentation The documentation for Mouse.Hit shows that it returns a CFrame, since you’re passing this to the server, you can just pass the CFrame value directly to the part you’re trying to update.

thing It works! also quick question… how cna i make it so the tool stays flat on the surface of each object. this is what it looks like:

Send the cframe’s position and set the object’s position instead.

FC:InvokeServer(mouse.Hit.Position)
StickyBomb.Position = mouse_pos
2 Likes

Try changing this

StickyBomb.CFrame = mouse_pos

to

StickyBomb.CFrame = CFrame.new(mouse_pos, Vector3.new(0,0,0))

it errors. it says the same error as before

Okay do what @flkfv said, that should work

1 Like