Humanoid Teleporting to Tool Handle Position

So I’m having issues with this Flying Dragon tool, where on equip you fly, and then on un-equip you stop. However, where ever you re-equip the tool, it sets your humanoid back to where that “unequip” just happened.

So you could be flying from miles away and then it would set you back to that Position after you equip it for the second time and so on.

Code →

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Mouse = Player:GetMouse()

local Flying = false

local Animation = script:WaitForChild("DragonAnim")
local LoadedAnim = Humanoid.Animator:LoadAnimation(Animation)

local Tool = script.Parent

local Handle = script.Parent.Handle

Tool.Equipped:Connect(function()
	
	
	
	Handle.Position = HumanoidRootPart.Position - Vector3.new(0,3,0)
	Handle.Orientation = HumanoidRootPart.Orientation + Vector3.new(0,0,0)
	local Weld = Instance.new("WeldConstraint")
	Weld.Part0 = HumanoidRootPart
	Weld.Part1 = Handle
	Weld.Parent = HumanoidRootPart
	
	if Flying == false then
		Flying = true

		local BodyVelocity = Instance.new("BodyVelocity")
		BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BodyVelocity.Parent = HumanoidRootPart
		LoadedAnim:Play()

		while Flying == true do
			BodyVelocity.Velocity = Mouse.Hit.LookVector * 50
			HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Mouse.Hit.Position)
			task.wait()
		end
	end
	
end)

Tool.Unequipped:Connect(function()
	
	if Character:FindFirstChild("Handle") then
		Character.Handle:Destroy()
	end
	
	if Flying == true then
		Flying = false
		LoadedAnim:Stop()
		HumanoidRootPart:FindFirstChildOfClass("BodyVelocity"):Destroy()
	end
	
end)

I tried CFrame? Still a little confused. Example below. OG marks the original position of when I unequipped. X marks the spot of where I was when I equipped it.


en

Can you send me a video of this bug?

Is your tool anchored? I know this is probably necessary but instead you could apply a VectorForce that counteracts gravity
For example, if gravity was 35, the VectorForce.Force property would be Vector3.new(0, 35 * part.AssemblyMass, 0)
Don’t forget to add an attachment!

https://gyazo.com/24a2ed38f191bdb2da3e26054e15696d

This happens when your tool is considered the root part of your character’s assembly. If your tool is anchored, make sure it’s not anchored while equipped. If not, change the RootPriority of the handle down to -1 (if you have other parts, make sure they are also set to -1). If you still encounter issues, make the handle and other parts massless.

2 Likes

Every time you equip you create a new loop.

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Mouse = Player:GetMouse()

local Flying = false

local Animation = script:WaitForChild("DragonAnim")
local LoadedAnim = Humanoid.Animator:LoadAnimation(Animation)

local Tool = script.Parent

local Handle = script.Parent.Handle

Tool.Equipped:Connect(function()
	
	
	
	Handle.Position = HumanoidRootPart.Position - Vector3.new(0,3,0)
	Handle.Orientation = HumanoidRootPart.Orientation + Vector3.new(0,0,0)
	local Weld = Instance.new("WeldConstraint")
	Weld.Part0 = HumanoidRootPart
	Weld.Part1 = Handle
	Weld.Parent = HumanoidRootPart
	
	if Flying == false then
		Flying = true

		local BodyVelocity = Instance.new("BodyVelocity")
		BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BodyVelocity.Parent = HumanoidRootPart
		LoadedAnim:Play()
	end
	
end)

Tool.Unequipped:Connect(function()
	
	if Character:FindFirstChild("Handle") then
		Character.Handle:Destroy()
	end
	
	if Flying == true then
		Flying = false
		LoadedAnim:Stop()
		HumanoidRootPart:FindFirstChildOfClass("BodyVelocity"):Destroy()
	end
	
end)

while Flying == true do
	BodyVelocity.Velocity = Mouse.Hit.LookVector * 50
	HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Mouse.Hit.Position)
	task.wait()
end

The script sets the position of the “Handle” object to the position of the player’s “HumanoidRootPart” minus a constant offset vector (0,3,0) when the tool is equipped. However, it does not reset the position of the handle when the tool is unequipped, so it will remain at the modified position. This could cause the player’s character to teleport to the handle’s position when the tool is re-equipped.

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