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!