Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get a Changed event to work with BasePart.Velocity?

Asked by 4 years ago
script.Parent.Parent.Parent.DriveSeat.Velocity:Connect(function()

this is what I have currently for this, and I am currently lost as the API reference doesn't help at all.

3 answers

Log in to vote
1
Answered by 4 years ago

You can either use .Changed or :GetPropertyChangedSignal("Property"), either way works.

script.Parent.Parent.Parent.DriveSeat:GetPropertyChangedSignal("Velocity"):Connect(function()
    --// Code
end)

Hope this helped! Don't forget to select this as the answer if this worked for you!

Ad
Log in to vote
0
Answered by 4 years ago

What if you just add-in an if statement like if script.Parent.Parent.Parent.DriveSeat.Velocity ~= 0 then --Code end

Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago

The problem:

Unfortunately as far as I know this is not currently possible as Velocity just like Position updates so often that it would fire way too often and would be too much overhead

The solution:

the only way to work around this is as far as I know is to use a while loop or a RunService Event i.e. Heartbeat and compare the last Velocity with the current Velocity

Example Heartbeat Code:

You can find an example for how to use Heartbeat here

Don't forget to mark my answer as the solution and upvote it if it helped :)

Answer this question