I have a moving platform that plays a sound the moment it begins moving with a Prismatic Constraint
I want that sound to stop moving the moment it reaches it finishes reaching its target position
I have tried:
Getting the position it moves to and checking when it reaches that position using repeat task.wait() until example_platform.Position == super_specific_position
However, that doesnt work because it changes ever so slightly by like 10 decimal spaces
Using the starting position subtracted by an empty Vector3 and getting the magnitude of it
It never worked, or maybe I was doing it wrong??
If there is a slight mistake Im doing or if I should approach this completely different, please tell.
Any help is appreciated.
Put a script in the part that is moving, and paste this:
local run = game:GetService("RunService")
local value = script.Value
local point = game.Workspace.Point -- replace "Point" with the name of the certain point you're mentioning
run.Heartbeat:Connect(function()
value.Value = math.floor(script.Parent.AssemblyLinearVelocity.Magnitude*1)
if value >= 0 then
script.Parent.Sound:Play()
end
end)
point.Touched:Connect(function(part)
if part == script.Parent then
sound.Stop()
end
end)
I’ll be honest, I didn’t fully implement your entire solution, but the part that helped me out the most was math.floor(script.Parent.AssemblyLinearVelocity.Magnitude*1)
Again, thank you so much for the help. Also, sorry for the delay.
I hope you have a great day and so on.