I’m trying to clone an object when an audio gets loud enough
For some reason my script isn’t working, and I don’t know what I did wrong.
This is the script:
local part = game.Workspace.Part
local Sound = game.Workspace.Sound
if Sound.PlaybackLoudness > 100 then
local clonedObject = part:Clone()
clonedObject.Parent = game.Workspace
clonedObject.Position = Vector3.new(-55.1, 5, 23.1)
end
Since it’s not working, I’m pretty sure I didn’t do something correctly, but I have no idea what it is
local run = game:GetService("RunService")
local part = workspace.Part
local sound = workspace.Sound
if script:IsA("Script") then
run.Heartbeat:Connect(function()
if sound.PlaybackLoudness > 100 then
local partClone = part:Clone()
partClone.Position = Vector3.new(-55.1, 5, 23.1)
partClone.Parent = game.Workspace
end
end)
elseif script:IsA("LocalScript") then
run.RenderStepped:Connect(function()
if sound.PlaybackLoudness > 100 then
local partClone = part:Clone()
partClone.Position = Vector3.new(-55.1, 5, 23.1)
partClone.Parent = game.Workspace
end
end)
end
It worked, but I can’t edit the cloned part using the script, is there a reason for this?
local run = game:GetService("RunService")
local part = game.Workspace.Part
local sound = workspace.Sound
if script:IsA("Script") then
run.Heartbeat:Connect(function()
if sound.PlaybackLoudness > 900 then
local partClone = part:Clone()
partClone.Position = Vector3.new(-55.1, 5, 23.1)
partClone.Parent = game.Workspace
partClone.Script.Disabled = false
wait(3)
partClone:Destroy()
end
end)
elseif script:IsA("LocalScript") then
run.RenderStepped:Connect(function()
if sound.PlaybackLoudness > 900 then
local partClone = part:Clone()
partClone.Position = Vector3.new(-55.1, 5, 23.1)
partClone.Parent = game.Workspace
partClone.Script.Disabled = false
partClone.Size = partClone.Size + Vector3.new(1,1,1)
wait(3)
partClone:Destroy()
end
end)
end
As you can see, I added a 3 second wait and then destroyed the part. It doesn’t work though, any idea why?