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

Audio Help Please? [DESC]

Asked by 9 years ago

EVERYBODY STOP -1 ON ALL MY POSTS ITS STUPID AND VERY ANNOYING! I am trying to figure out if it's possible that if a player gets close to a part, a sound plays. But if the player goes away from the part, the sound doesnt play. Any help please?

0
Stop screaming at others. All users are free to - points on your posts. And simply calling them annoying will get you more. BosswalrusTheCoder 88 — 9y

2 answers

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

We can find the magnitude (distance) between a character's position and the part using the property of Vector3s, magnitude.

local player = game.Players.LocalPlayer -- Must be a local script
local part = game.Workspace.Part -- Part that makes the sound play
local distance = 15 -- Studs away needed to make sound play
local sound = game.SoundScape.Sound -- Sound you want to play

while true do -- There are more efficient ways to check more than once, but this will work
    if (player.Character.Torso.Position - part.Position).magnitude <= distance and sound.IsPaused then
        sound:Play()
    elseif (player.Character.Torso.Position - part.Position).magnitude > distance and sound.IsPlaying then
        sound:Pause()
    end
    wait()
end


0
I put that in a part, but the sound never played. Any help? PyccknnXakep 1225 — 9y
0
You have to edit it to suit your needs BlackJPI 2658 — 9y
Ad
Log in to vote
0
Answered by
NotSoNorm 777 Moderation Voter
9 years ago

Put the sound in the part and edit the volume, boom.

Answer this question