Viewport playing sound from player's tools

For some reason, the viewport will duplicate the audio from the tools of the player. How do I fix this? I tried fixing it, but didn’t work. Any help is greatly appreciated!

local viewPortFrame = script.Parent:WaitForChild("ViewportFrame")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true

local newCamera = Instance.new("Camera")
newCamera.Parent = viewPortFrame
viewPortFrame.CurrentCamera = newCamera

local clonedChar
game:GetService("RunService").RenderStepped:Connect(function()
	if clonedChar then clonedChar:Destroy() end
	clonedChar = char:Clone()

	local hrp = clonedChar:WaitForChild("HumanoidRootPart")

	newCamera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 4) + Vector3.new(0,2,0) + (hrp.CFrame.RightVector * 2), hrp.Position) 
	clonedChar.Parent = viewPortFrame
end)

for i, v in pairs(char:GetDescendants()) do
	if v:IsA("Sound") then
		v:Destroy()
	end
end

Does the view port frame have a child of a sound? Because when you clone something your cloning it children as well.

Your also cloning the character with all of its sounds in it first then deletong the sounds on the original but not the clone.

The viewport frame does not have any sound children. I’m just trying to make it so it reaches the sounds in the tools.

1 Like

Does it have something to do with you making the char. savable? I’m not sure but I don’t think the player is normally Archivable and I’ve never seen this bit of code used before in a script like this.

I’m just wondering if because you’ve got a saved version of the player when the player dies there are items left over in the workspace after the LocalPLayer dies.

Also, you are setting clonedChar.Parent = veiwPortFrame, but then Destroying sounds in char instead.

I tried fixing it. It stops playing the audios, but now it just stops playing it entirely. I tried your suggestions but didn’t seem to work.

local viewPortFrame = script.Parent:WaitForChild("ViewportFrame")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true

local newCamera = Instance.new("Camera")
newCamera.Parent = viewPortFrame
viewPortFrame.CurrentCamera = newCamera

local clonedChar
game:GetService("RunService").RenderStepped:Connect(function()
	if clonedChar then clonedChar:Destroy() end
	clonedChar = char:Clone()

	local hrp = clonedChar:WaitForChild("HumanoidRootPart")

	newCamera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 6) + Vector3.new(0,2,0) + (hrp.CFrame.RightVector * 2), hrp.Position) 
	clonedChar.Parent = viewPortFrame
end)

while true do
	task.wait(1)
for i, v in pairs(char:GetDescendants()) do
	if v:IsA("Sound") then
		v.Volume = 0
	end
end
end

Fixed it, and whoever has the same issue in the future. Here is how I fixed it:

local viewPortFrame = script.Parent:WaitForChild("ViewportFrame")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true

local newCamera = Instance.new("Camera")
newCamera.Parent = viewPortFrame
viewPortFrame.CurrentCamera = newCamera

local clonedChar
game:GetService("RunService").RenderStepped:Connect(function()
	if clonedChar then clonedChar:Destroy() end
	clonedChar = char:Clone()

	local hrp = clonedChar:WaitForChild("HumanoidRootPart")

	newCamera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 6) + Vector3.new(0,2,0) + (hrp.CFrame.RightVector * 2), hrp.Position) 
	clonedChar.Parent = viewPortFrame
end)


while true do
	task.wait(1)
for i, v in pairs(viewPortFrame:GetDescendants()) do
	if v:IsA("Sound") then
		v.Volume = 0
	end
end
end

So basically what I mentioned in the last line of my post? :wink:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.