How do I prevent character from teleporting to welded object unless told to do so

I want the character to teleport to the thrown object after a certain button is pressed only if it’s welded, but the issue is that I can’t get the character to not teleport after the object is welded to a humanoid
I tried doing an if statement for the welding so that if it’s welded then the character cannot move but it still didn’t work.

This is the script for the tool

local Kunai = game.ServerStorage:FindFirstChild("Kunai")
local Tool = script.Parent
Cooldown = false
CDTime = .5


Tool.kunai.OnServerEvent:Connect(function(Player,Mouse)
	if Cooldown then return end
	local char = Player.Character
	local newKunai = Kunai:Clone()
	local position = char.Head.Position + CFrame.new(char.Head.Position,Mouse.p).lookVector * 1 
	newKunai.CFrame = CFrame.new(position,Mouse.p) * CFrame.new(0,0,-3)
	--newKunai.CFrame = char.RightHand.CFrame * CFrame.new(0,0,-3)
	--newKunai.CFrame = char.RightHand.CFrame * CFrame.Angles(0,math.rad(90),0)
	
	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.MaxForce = Vector3.new(5000,5000,5000)
	bodyVelocity.Velocity = Mouse.lookVector*100
	bodyVelocity.Parent = newKunai
	
	newKunai.Parent = workspace
	newKunai.Touched:Connect(function(hit)
		print(hit)
		if hit.parent:FindFirstChild("Humanoid")then
			--wait(.5)
			newKunai.CFrame = hit.CFrame
			local weld = Instance.new("Weld")
			weld.Part0 = hit
			weld.Part1 = newKunai
			weld.Parent = newKunai
			end
			
	
	end)
	wait(2)
		char.UpperTorso.CFrame = newKunai.CFrame
		newKunai:Destroy()
	Cooldown = true
	wait(CDTime)
	Cooldown = false
end)

and this is the local script for the tool

local Tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
wait(1)
local animation = script.Animation
local char = player.Character
local hum = char:WaitForChild("Humanoid")

local animTrack = hum:LoadAnimation(animation)

Tool.Activated:Connect(function()
	Tool.kunai:FireServer(mouse.Hit)
	animTrack:Play()
end)

I’ve been on this problem for a while now so I’m not sure what to do, any suggestions will do.
Thanks!

2 Likes

Could you explain a little bit better please? I don’t understand what you’re trying to do. (Not trying to be rude)

I can’t script at all, so I am sorry if this is unhelpful. I think you just do if then else then
It basically will make it so if the button is not clicked it won’t teleport you because you specify that if the button is not pressed it will keep you where you are. Again sorry if this doesn’t help. I code on other websites so I don’t know if you can do this with lua.

1 Like

So basically I’m trying to make a throwable knife that allows you to teleport after a certain time, but if it’s welded to a person or a dummy then it shouldn’t teleport until I press a certain button. I tried using an if statement for the last part but it still didn’t work

I figured it out, thanks ya’ll