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 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