Hello! I’m not a good coder so I really need help to solve this issue. I’m currently trying to make a falling ceiling (as seen in the video) that would make a noise (like a crushing noise) when it hits the ground. I also want it to play a sound whenever it’s moving and when it stops moving, I want that sound to stop.
I’ve tried creating a function and also tried the “while true do” loop but none of them worked since they crash when they run, although I needed the script to continuously check if the " falling part " was in the correct position to make that sound somehow.
I’ve tried to search for many different solutions but couldn’t find any good ones since some of them are simply too complicated for me and some of them were just not the solution I was looking for.
(I also made the part fall by using an animation editor if that changes anything)
Also, this is the failed code I’ve tried by using a function.
local position = script.Parent.Position
local function check()
if position.Y <= -139 then --The Y position of the part when it hits the ground
script.Parent.CrashSound:Play() --CrashSound is the sound when I want it to play whenever the part hits the ground
while script.Parent.CollapseSound.Volume > 0 do --CollapseSound is the sound that's playing constantly when the part is moving
script.Parent.CollapseSound.Volume -= 0.3
wait(0.05)
end
end
if position.Y >= -138 then --The Y position of the part when it's moving
while script.Parent.CollapseSound.Volume < 2 do
script.Parent.CollapseSound.Volume += 0.3
wait(0.05)
end
end
if position.Y >= -108 then --The Y position of the part when it hits the ceiling
while script.Parent.CollapseSound.Volume > 0 do
script.Parent.CollapseSound.Volume -= 0.3
wait(0.05)
end
end
check() --Doing this causes a crash as expected and it is technically fixable by putting a "wait" command but I need the script to check constantly
end
check()
I would highly appreciate if you helped me!
I’m sorry for those coders out there who are disappointed by reading this lol.
I’ve read that .Touched event would not be efficient for situations like these before in another forum so I’ve skipped trying it. Although if I were even to use it I don’t know how I would write it. I also have never heard of “getpropertychangedsignal” before so I can also try search that now.
I don’t know if me using an animation would affect anything since it also changes the positions of the part in the properties section like how it would by using TweenService or something. Also I’m pretty sure the sound itself is fine since I can hear it using other codes.
Anyways, I’m going to try the “.Touched” command now and see what happens. I will make sure to report the result like I’ve said.
So I realized that I’ve used more than 1 part to make the floor. I needed to get all the parts that were named “CaveFloor” and so I’ve researched how to do it. I’ve seen people use :GetDescendants command so I got a code that I_eif has made to help someone else. I seperated my script into 2, one of them checking if the part is moving and one of them checking if the ceiling hits the floor (that being the script I’ve basically copy and pasted, with the .Touched command). Unfortunately, it did not work and I want you guys to let me know what might’ve went wrong.
The script that checks if the part has touched the floor:
local part = script.Parent
for _, descendant in pairs(workspace:GetDescendants()) do
if descendant.Name == "CaveFloor" then
descendant.Touched:Connect(function(hit)
if hit.Name == "FallingPart" then
print("crash!")
script.Parent.CrashSound:Play()
end
end)
end
end
the script that checks if the part is moving:
local position = script.Parent.Position
local function check()
if position.Y == -139.773 and position.Y == -106.516 then --The Y position of the part when it hits the ground & the ceiling
script.Parent.CollapseSound.Volume = 0
end
if position.Y < -106.516 and position.Y > -139.773 then --The Y position of the part when it's moving
script.Parent.CollapseSound.Volume = 2
end
wait(0.1)
check()
end
check()
There are no errors, no prints, the “CollapseSound” keeps playing even though it is supposed to stop whenever it reaches the ceiling and the floor. Also the “CrashSound” doesn’t play either.
I’ve forgotten about this topic completely, It’s still unsolved. I’ve found an easy solution already and It’s to do with GetMarkerReachSignal. You can just add events into the animations and call them with this code in a script. It’s really useful, definitely recommend it.
(Sorry for bumping the topic. I don’t know if I could’ve deleted it.)