Magnitude doesnt work

basically, the sound wont play or get louder at all, no errors:

local player = game:GetService("Players").LocalPlayer

local sound = workspace.Main["around the clock glovey theme"]

local runService = game:GetService("RunService")

local MagnitudePart = workspace.Main

runService.RenderStepped:Connect(function()
	local magnitude = (MagnitudePart.Position - player.Character.Head.Position).Magnitude
	if magnitude <= 40 then
		sound:Play()
	elseif magnitude > 40 then
		sound:Stop()
	end
end)
1 Like

Try getting another variable for the character like this;

local char = player.Character or player.CharacterAdded:Wait()

2 Likes

Have you tried prints to see if the code is running?

local player = game:GetService("Players").LocalPlayer

local sound = workspace.Main["around the clock glovey theme"]

local runService = game:GetService("RunService")

local MagnitudePart = workspace.Main

runService.RenderStepped:Connect(function()
	local magnitude = (MagnitudePart.Position - player.Character.Head.Position).Magnitude
	if magnitude <= 40 then
        print("playing sound")
		sound:Play()
	elseif magnitude > 40 then
        print("don't play sound")
		sound:Stop()
	end
end)
2 Likes

printing works, i just cant hear the sound, and no, the volume isnt at 0, its at 1

1 Like

that doesnt change anything, could it be where the sound is parented?

1 Like
local player = game:GetService("Players").LocalPlayer

local sound = workspace.Main["around the clock glovey theme"]

local runService = game:GetService("RunService")

local MagnitudePart = workspace.Main

runService.RenderStepped:Connect(function()
	local magnitude = (MagnitudePart.Position - player.Character.Head.Position).Magnitude
	if magnitude <= 40 then
        sound.Playing = true
		sound:Play()
	elseif magnitude > 40 then
		sound:Stop()
	end
end)

Check if your roblox volume is off.
If this doesn’t work, then try to place the sound in soundservice.

1 Like

print magnitude to see what it is

print(magnitude)
1 Like

wouldnt placing the sound in sound service defeat the whole purpose lol, and my volume is on, i can hear other sounds

the magnitude is fine, its just the sound

Maybe there is something wrong with the sound itself?

i found out the problem, its the loop, it loops the sound so much you cant hear it, but without the loop, it doesnt work.

It would most likely be an issue with loop playing the sound, as running the Play() function will reset it from start.

if magnitude <=40 then
    if not sound.Playing then
        sound:Play()
    end
elseif magnitude > 40 then
    if sound.Playing then
        sound:Stop()
    end
end
1 Like

cool, now how would i make the sound get louder or faster depending on how close your are?

Use Sound.Volume it should be what you are looking for.

i get that, its the:

that i dont know much on how to do, could it be using " * "

Oh yea you need to figure out some formula for it :D.

1 Like