Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I check if an object's velocity changes to 0?

This local script is in starter character.

local Char = script.Parent

for _,v in pairs(Char:GetChildren())do
	if v:IsA("BasePart") then
		v.Touched:Connect(function()
			if Char.UpperTorso.Velocity.Y <= -100 then
				Char:FindFirstChild("Humanoid").Health = 0
			end
		end)
	end
end

How do I check if that velocity suddenly changes to 0 (as in the person has stopped falling)?

1 answer

I think the best way to do this would be something like this

local loop = true
local vel
local pos1
local pos2

local function Check()
	pos1 = Char.UpperTorso.Position
	wait(.1)
	pos2 = Char.UpperTorso.Position
	repeat
		wait()
		if pos1 == pos2
			Char:WaitForChild('Humanoid').Health = 0
			loop = false
		else
			print('Still Falling') --Just to check if it's working. (The print function is good for checking if a function or something is working)
	until loop == false
end

for _,v in pairs(Char:GetChildren())do
    if v:IsA("BasePart") then
        v.Touched:Connect(Check)
    end
end

Don't know if it'll work. If it doesn't you get the idea of what i'm trying to do

5 comments

0

I'll be back in 10 min. to check any comments

0

Won't be here till 3:50 p.m. Eastern Time

0

this is a bad idea because of floating point errors and you only check once.

0

Funny that vel is never defined...so why do you even have it in the script?

0

Oh, i was going to use it but the final product of the script didn't need it and I forgot to delete it

This discussion is preserved as it was. New answers, comments, and votes are closed.