Script not anchoring part

You can write your topic however you want, but you need to answer these questions:

im trying to make a placeable tool…

  1. What do you want to achieve? Keep it simple and clear!
    I want to anchor my tool handle as soon as i click to place it on the ground

  2. What is the issue? Include screenshots / videos if possible!
    when I click to place the tool it refuses to anchor the part, and the tool slides on the floor if im moving.

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to make sure that the code was getting run with print functions. it seems to ignore the line of code that anchors the handle, but still prints.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
I’m trying to make a tool that you can place anywhere as long as it is close enough to your character. I used a remote event with a server script to actually place the thing, and a localscript inside the tool for everything else. (finding the mouse position, displaying a preview, etc.)

This is the local script inside the tool,


	local player = game:GetService("Players").LocalPlayer
	local tool = script.Parent
	local replicatedStorage = game:GetService("ReplicatedStorage")
	local runService = game:GetService("RunService")
	local rootPartPosition
	local mousePos


	tool.Unequipped:Connect(function() --to unanchor if the tool is dropped
		tool.Handle.Anchored = false
	end)

	tool.Equipped:Connect(function()
		tool.Handle.Anchored = false
		print("unanchored")
	end)


	tool.Activated:Connect(function()
		rootPartPosition = player.Character.HumanoidRootPart.CFrame.Position
		mousePos = game.Players.LocalPlayer:GetMouse().Hit.Position
		if math.abs(mousePos.X - rootPartPosition.X) <= 10 and math.abs(mousePos.Y - rootPartPosition.Y) <= 10 and math.abs(mousePos.Z - rootPartPosition.Z) <= 10 then
			lookPart.Transparency = 1
			replicatedStorage.Place:FireServer(mousePos, tool)
		else return end
	end)

and the server sided script that places the tool;

	local Place = game:GetService("ReplicatedStorage").Place

	Place.OnServerEvent:Connect(function(plr, mousepos, tool)
		tool.Parent = workspace
		tool.Handle.Anchored = true
		print("anchored")
		tool.Handle.CFrame = CFrame.new(mousepos)
	end)

any help is appreciated.

Edit; i ended up figuring out that the handle is being placed and anchored correctly on server-side, but not for the client. this doesn’t solve the issue but i thought it would be helpful to know

1 Like

Your anchoring the tool rather than a separate part which would cause complications. I would suggest using a tool on the client side but creating a new part and giving it the handles properties on the server side to anchor.

Edit: Sorry for being a bit unclear, I made an explanation below to explain the issue, this is what I determined is going on from the video and the code:

  1. Tool is used to find position
  2. Player clicks mouse, message is sent to server
    This part works fine then:
  3. Server gets message and anchors the tool handle to the ground
  4. When the player moves core scripts come into play and move the handle back to player.

So what you need to do is either what I said above or to turn of required handle on the tool so that core scripts dont weld it to the players hand.

You simply need to set the new part’s AssemblyLinearVelocity and AssemblyAngularVelocity both to Vector3.zero.

I found the solution! It was actually quite simple. I had placed the bit of code that unanchors the Handle inside the local script (so it only happened on the client). This means that on the server side, the handle was never unanchored in the first place, and the server wasn’t reanchoring the Handle which led to it sliding around.

I fixed this by deleting the line of code in the localscript that unanchors the Handle;

--All of this got deleted
    tool.Unequipped:Connect(function()
		tool.Handle.Anchored = false
	end)

	tool.Equipped:Connect(function()
		tool.Handle.Anchored = false
		print("unanchored")
	end)
--^^^^

And used the server sided script to unanchor the Handle after it was picked up again.

	local Place = game:GetService("ReplicatedStorage").Place
	local runService = game:GetService("RunService")

	Place.OnServerEvent:Connect(function(plr, mousepos, tool)
		tool.Parent = workspace
		tool.Handle.Anchored = true
		tool.Handle.CFrame = CFrame.new(mousepos)
		**while tool.Parent == workspace do**
**			runService.Heartbeat:Wait()**
**		end**
**		tool.Handle.Anchored = false**
**	end)**

(the loop waits until the tool is picked up, and then ends, Which executes the final line of code that unanchors the Handle.)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.