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

Play sound localy between 2 height limits?

Asked by 4 years ago
Edited 4 years ago

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 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
I did everything but it says Looping is not a valid member of Sound admiral2001 36 — 4y
0
Yeah, there was an API change, since the last time I looked at it, Looping should be just Looped. Try Now. SimplifiedCode 227 — 4y
0
Did it work? If it did, I'd appreciate if you marked my answer as "accepted". SimplifiedCode 227 — 4y
Ad

Answer this question