Hello im making a car where when you sit it plays music but i cannot seem to find out how to stop the music when the player jumps out.
This is my code (keep in mind this is in the car handler script not a local script)
is that if
statement in a loop? if not then it will just only check once. You need to loop the if
statement using whatever method you like.
So i did a while true do loop on the if statement and the music just overlaps infinitely now.
can’t you show the full code, without a screenshot?
Like the whole entire car handler? Or writing the if statement in dev forum?
I think this might be what you’re looking for:
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if (seat.Occupant) then
--entered seat
else
--exited seat
end
end)
It detects when the occupant changes.
just use :GetPropertyChangedSignal()
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
CD:Play()
wait(5)
RBR:Play()
RBR.Looped = true
else
RBR:Stop()
RBR.Looped = false
end
end)
Edit: @BizBazarr beat me to it.
btw if you don’t want the song to restart you can do Song.Playing = false, this will simply pause it
Well now it plays no music at all no errors at all.
And yes i did change the script.parent to seat.
If you haven’t found anything that fixes this you can try the following
while true do
wait()
if (seat.Occupant) and RBR.Paused then
-- do what you want whenever there is an occupant
else
-- whatever happens when there is no an occupant
end
Which is the music, the CD
or the RBR
? Because if you want the CD
to stop you should ad a CD:Stop()
after the else. Also is there a specific reason you want change the looped property of RBR
?
CD is a countdown RBR is the music.
I already tried that the first time it just makes the music overlap.
Are u only playing the music in a server script or in a local script aswell?
It says it tin the post its a regular script not a local.
Did u try to do it like this
RBR.Looped = false
RBR:Stop()
Cuz like this i think it will first stop it but cuz its looped it will run again
RBR:Stop()
RBR.Looped = false
Didnt work it still plays when i jump out.
add a print before u that line of code where u stop it and see if it prints or not
I think i found the problem the problem is that its not even working its not printing somehow.