Hello Developers,
I'm looking to make a script that plays a scary heartbeat sound to players who are close to the murderer player.
Could anyone help or suggest how I can make this; all my attempts have failed miserably!
Thanks
--LocalScript in ReplicatedFirst local Players=game:GetService"Players" local Player=Players.LocalPlayer local function onCharacterAdded(char) local player=Players:GetPlayerFromCharacter(char) if player==Player then return end local sound=Instance.new("Sound",wait()and char.PrimaryPart) sound.SoundId="rbxassetid://1839943553" sound.Looped=true local backpack=player.Backpack --local knife=not player.Innocent.Value local knife; backpack.ChildAdded:Connect(function(v) --if v.Name=="Knife"then knife=v end knife=v end) --knife=backpack:FindFirstChild"Knife" knife=backpack:FindFirstChildOfClass"Tool" local hrp,hrp2=char.PrimaryPart,(Player.Character or Player.CharacterAdded:Wait()):WaitForChild("HumanoidRootPart",Players.RespawnTime+1) coroutine.wrap(function() while(char.Parent and wait(2))do sound.Playing=knife and (hrp.Position-hrp2.Position).magnitude<40 or false end end)() end local function onPlayerAdded(player) player.CharacterAdded:Connect(onCharacterAdded) local char=player.Character if char then onCharacterAdded(char) end end Players.PlayerAdded:Connect(onPlayerAdded) for _,v in ipairs(Players:GetPlayers())do onPlayerAdded(v) end
I think it is possible to add a part inside the murderer that plays a heartbeat sound constantly nearby. First, you have to get the character of the murderer, and put it inside a variable. I'm going to name this variable murderer
, but it has not been actually defined in the code block I am going to be writing in. Also, make sure to replace "rbxassetid://176554627"
with your asset id inside quotes. If you want to, you can change the maximum distance (in studs) you can hear the heartbeat inside line 12.
Here is the script:
local part = Instance.new("Part") part.Name = "Heartbeat Storer" part.Anchored = false part.CFrame = murderer:WaitForChild("HumanoidRootPart").CFrame part.Parent = murderer part.Transparency = 1 local sound = Instance.new("Sound") sound.Name = "Heartbeat Sound" sound.Parent = part sound.RollOffMode = Enum.RollOffMode.Linear sound.RollOffMaxDistance = 100 sound.SoundId = "rbxassetid://176554627" sound.Looped = true sound:Play() local weld = Instance.new("WeldConstraint") weld.Name = "HeartbeatWeld" weld.Part0 = part weld.Part1 = murderer:WaitForChild("Torso") or murderer:WaitForChild("UpperTorso") weld.Parent = murderer