So, I’ve been working on this script that plays a random sound every time it’s clicked then it waits for a denounce. This script works for everything else ever since the update of Roblox Studio. When I tried to use the script again on another part, it works only like a limited amount of times until I get this one specific error that checks if the “IsPlaying” property of the sound is false; it checks if the HingeConstraint is less than 0. If it is false, it will play again. But for some reason, it works only once or twice then gives me this error:
How could it possibly work twice? But sooner defined ‘IsPlaying’ as nil. Then it won’t run ever again in the game.
Here’s the script:
local MusicTable = {"HammerHitSound", "HammerHitSound", "HammerHitSound","HammerHitSound", "SquishyPunch"," SquishyPunch", "BoneBreakingHitSoundFX"}
local Folder = workspace:FindFirstChild("WipeoutSounds")
local Constraint = script.Parent.Parent.Parent.Parent.HammerHinge.HingeConstraint
local db = false
script.Parent.Touched:Connect(function(plr)
if db == false and plr.Parent:FindFirstChild("Humanoid") and Constraint.TargetAngle < 0 then
db = true
local Music = Folder:FindFirstChild(MusicTable[math.random(1, #MusicTable)])
if Music.IsPlaying == false then
Music:Play()
wait(1.5)
db = false
end
end
end)