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

Audio Help Please? [DESC]

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?

1 comment

0

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

2 answers

✓ Accepted answer

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


2 comments

0

I put that in a part, but the sound never played. Any help?

0

You have to edit it to suit your needs

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

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