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

Play sound localy between 2 height limits?

Hello Im trying to make a script for my sub game. The idea is that there should be a sound between two height limits. Like in shallow water there is one sound and when in deeper there is another sound. Only the player whos in that hight limit should hear that sound and others who arent shouldnt. The sound should also loop as long as the player is in that area and should stop if the player left the area. So is it possible to make this script? If someone could help me with this I would be really grateful.

1 comment

1 answer

✓ Accepted answer

The way I would do it would be the camera position, and if the y coordinate is below a certain point then it will switch the sound.

Heres an example:

-- Local Script

cam = game.Workspace.CurrentCamera
minheight = 5 -- height (in studs) before it plays the deep sound
sound = script.Parent.Sound -- location of the sound (put it somewhere on the client like StarterGui)
deepsound = "" -- the sound of when the sub is deep
shallowsound = "" -- the sound of when the sub is in shallow

sound.Looped = true

while true do
	if cam.CoordinateFrame.Position.Y <= minheight then
		sound:Stop()
		sound.SoundId = deepsound
		sound:Play()
	else
		sound:Stop()
		sound.SoundId = shallowsound
		sound:Play()
	end
end

3 comments

0

I did everything but it says Looping is not a valid member of Sound

0

Yeah, there was an API change, since the last time I looked at it, Looping should be just Looped. Try Now.

0

Did it work? If it did, I'd appreciate if you marked my answer as "accepted".

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