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

Trying to repeat sound faster/slower the closer/further you are to the NPC's head?

Asked by 7 years ago

This script is practically thanks to my friend, but as a challenge, I decided to see if I can implement the repeating faster and slower sound (as explained in the title). Problem is, I was stuck pretty much instantly and decided to come here to see if anybody else knew the problem, I will provide all of the script here, but it's pretty much notably the spawn(function() part. The example is shown below:

local Player = game:GetService("Players").LocalPlayer;
local PlayerGui = Player:WaitForChild("PlayerGui");
local Sound = Instance.new("Sound", PlayerGui);
Sound.SoundId = "rbxassetid://1011469175";
Sound.Volume = 1;
Sound.Looped = false;

local NPC = workspace:WaitForChild("EliteBananaSquad");
local NPC_Head = NPC:WaitForChild("Head");

local Character = Player.Character or Player.CharacterAdded:Wait();
local Head = Character:WaitForChild("Head");

Player.CharacterAdded:Connect(function(New_Character)
    Character = New_Character;
    Head = Character:WaitForChild("Head");
end);

spawn(function()
    while (true) do
       Sound:Play();
       wait((Head.Position - NPC_Head.Position).Magnitude)
    end
end);

while (wait()) do
    if (Head) then
        Sound.Volume = math.clamp(1 / (Head.Position - NPC_Head.Position).magnitude, 0, 1);
    end
end

0
; CootKitty 311 — 7y
0
Still didn't do anything sadly :( Plutoeros 2 — 7y

Answer this question