How to make active BodyVelocity after 2 seconds?

I dont want touch to tornado because whenever a player touchs the tornado,player is flying

This is the script

	game.Lighting.RuzgarDalgasiRemote.OnServerEvent:Connect(function(Player)
	local Properties = {
		Velocity = 110,
		Duration = 0.25,
		Cooldown = 1,
		}
	local pART = game.Lighting.RuzgarTest:Clone()
	
	local BodyVelocity = Instance.new("BodyVelocity",pART)
	
	BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge) * 15000 
	pART.CFrame = Player.Character.HumanoidRootPart.CFrame + Player.Character.HumanoidRootPart.CFrame.lookVector * 110
	BodyVelocity.Velocity = pART.CFrame.LookVector * Properties.Velocity
	BodyVelocity.Parent = pART
	pART.Position = Player.Character.Head.Position
	local Touched = pART.Touched
	pART.Parent = game.Workspace
	pART.CanCollide = false
	pART.Massless = true
	pART.CanTouch = false
	
	 if  pART.Touched then
		wait(1)

		--here is the touched script
		local velocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)	
		
		velocity.Velocity = Vector3.new(0,40.0)
	wait(1)
		velocity:Destroy()
		
	end
	---------------------------------------------
	
	while true do
		pART.CFrame = pART.CFrame * CFrame.fromEulerAnglesXYZ(0,0.3,0)
		wait(0.01)
		pART.CFrame = pART.CFrame * CFrame.fromEulerAnglesXYZ(0,0.3,0)
	end
	

		wait(1)		
			pART:Destroy()
	
	wait(Properties.Duration)
		BodyVelocity:Destroy()
end)
	if  pART.Touched then
		wait(1)

		--here is the touched script
		local velocity = Instance.new("BodyVelocity")	
		task.wait(2)
		velocity.Parent = Player.Character.HumanoidRootPart
		velocity.Velocity = Vector3.new(0,40.0)
		wait(1)
		velocity:Destroy()

	end

Just cause the main thread to yield for 2 seconds before parenting the BodyVelocity instance.

1 Like
local rs = game:GetService("ReplicatedStorage")
local RD = rs:WaitForChild("RuzgarDalgasiRemote")
local part = rs:WaitForChild("RuzgarTest")

RD.OnServerEvent:Connect(function(Player)
	local Character = Player.Character
	local HRP = Character:WaitForChild("HumanoidRootPart")
	local Head = Character:WaitForChild("Head")

	local partClone = part:Clone()

	local BodyVelocity = Instance.new("BodyVelocity")
	task.wait(2)
	BodyVelocity.Parent = partClone
	BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	partClone.CFrame = (HRP.CFrame + HRP.CFrame.lookVector * 110)
	BodyVelocity.Velocity = partClone.CFrame.LookVector * 110
	partClone.Position = Head.Position
	partClone.Parent = workspace
	partClone.CanCollide = false
	partClone.Massless = true
	partClone.CanTouch = false

	local Touched = partClone.Touched
	if Touched then
		task.wait(1)
		local BodyVelocity2 = Instance.new("BodyVelocity")
		task.wait(2)
		BodyVelocity2.Parent = HRP
		BodyVelocity2.Velocity = Vector3.new(0, 40, 0)
		task.wait(1)
		BodyVelocity2:Destroy()
	end

	task.spawn(function()
		while task.wait() do
			if partClone then
				partClone.CFrame *= CFrame.fromEulerAnglesXYZ(0, 0.3, 0)
			else
				return
			end
		end
	end)

	task.wait(1)		
	partClone:Destroy()
	task.wait(0.25)
	BodyVelocity:Destroy()
end)

And some general cleaning up & fixing of a few things, if you have any questions don’t hesitate to ask.

1 Like

This seems like a bit overcomplicated script you’re managing, why not just check if the Tornado isn’t touching your own Player by using game.Players:GetPlayerFromCharacter(), referencing a table to see who touched it, and using a Connection?

local Properties = {
    Velocity = 100,
    Duration = 0.25,
    Cooldown = 1,
}

game.Lighting.RuzgarDalgasiRemote.OnServerEvent:Connect(function(Player)
    local Part = game.Lighting.RuzgarTest:Clone()
    Part.CFrame = Player.Character.HumanoidRootPart.CFrame
    Part.Position = Player.Character.Head.Position
    Part.CanCollide = false
    Part.CanTouch = false
    Part.Parent = workspace

    local BodyVelocity = Instance.new("BodyVelocity")
    BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge) --No need to multiply as math.huge is an EXTREMELY high number
    BodyVelocity.Velocity = Part.CFrame.LookVector * Properties.Velocity
    BodyVelocity.Parent = Part

    local Connection
    local Tagged = {}

    local function PlayerHit(Hit) 
        if Hit.Parent and Hit.Parent:FindFirstChild("HumanoidRootPart") then
            local PlayerTarget = game.Players:GetPlayerFromCharacter(Hit.Parent)
 
            if PlayerTarget and PlayerTarget ~= Player and not table.find(Tagged, PlayerTarget) then
               table.insert(Tagged, PlayerTarget)

               local Velocity = Instance.new("BodyVelocity")
               Velocity.Velocity = Vector3.new(0, 40, 0)
               Velocity.Parent = Hit.Parent.HumanoidRootPart
               wait(1)
               Velocity:Destroy()
            end
        end
    end)

    Connection = Part.Touched:Connect(PlayerHit)

    coroutine.resume(coroutine.create(function()
        while Part.Parent == workspace do
            Part.CFrame *= CFrame.fromEulerAnglesXYZ(0, 0.3, 0)
            game:GetService("RunService").Heartbeat:Wait()
        end
    end))

    wait(Properties.Duration)
    Connection:Disconnect()
    Part:Destroy()
end)

There were a couple of other minor issues I noticed, but go ahead and try this

1 Like