Tornado not knocking back

I’m currently creating a tornado that when touched it knocks the player back, but for some reason, it doesn’t activate when touched. Could someone help?

The script is a local script inside of a part.

function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    local character = part.Parent
    if character and character:FindFirstChild("HumanoidRootPart") then 
        local bodyVelocity = Instance.new("BodyVelocity")
        bodyVelocity.Velocity = Vector3.new(50, 0, 0) 
        bodyVelocity.Parent = character.HumanoidRootPart
        game.Debris:AddItem(bodyVelocity, 0.5) -- removing force after 0.5 seconds    
        print("HIT TORNADO")
    end
    if humanoid then    -- if a humanoid exists, then
        humanoid.Health = humanoid.Health - 50    -- damage the humanoid
    end 
end

script.Parent.Touched:connect(onTouch)
1 Like

just to make sure, it doesnt print out the “tornado hit” part? also, try making script.Parent.Transparency = 0.5 just for testing. you can see if youre even hitting it. maybe the part is unanchored and fell down, or isnt welded to the tornado.

1 Like

BodyVelocity is deprecated, you should use LinearVelocity instead.

Something like this:

local attachment = Instance.new("Attachment")
attachment.Parent = character.PrimaryPart
		
local linVel = Instance.new("LinearVelocity")
linVel.VectorVelocity = Vector3.new(50, 0, 0)
linVel.Attachment0 = attachment
linVel.MaxForce = 100000
linVel.Parent = character.PrimaryPart
game.Debris:AddItem(linVel, .5)
1 Like

Local scripts don’t work in the workspace. Switch it to a server script and use LinearVelocity since Body velocity is deprecated.

function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    local character = part.Parent
    if character and character:FindFirstChild("HumanoidRootPart") then 
        local LV = Instance.new("LinearVelocity")
        LV.MaxForce  = math.huge
        LV.VectorVelocity = -character.HumanoidRootPart.CFrame.LookVector * 50 —- nice addition to knock the player *backwards*
        LV.Parent = character.HumanoidRootPart
        game.Debris:AddItem(bodyVelocity, 0.5) -- removing force after 0.5 seconds    
        print("HIT TORNADO")
    end
    if humanoid then    -- if a humanoid exists, then
        humanoid.Health = humanoid.Health - 50    -- damage the humanoid
    end 
end

script.Parent.Touched:connect(onTouch)
1 Like

on top of this i recommend adding a debounce
the player is going to be touching this with multiple parts (right leg, left leg), which all count as touch
this will run onTouch() multiple times a second, instantly killing the player since your damage is so high

Thank you for the advice but I thought it too trivial for this occasion since I’m providing an example on how to use linear velocity. The OP will probably account for this later on

1 Like

your code is fine and an improvement, statement i made directed towards OP

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