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)
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.
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)
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