You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I need help debugging this script, it detects when the player is in ragdoll, then it will play a sound when the torso is touched.
What is the issue? Include screenshots / videos if possible!
The touched function in particular doesnt seem to be working
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried waiting for the sound to stop before adding it to debris, I’ve tried printing strings to help find when the Torso touched event is used. I’ve also tried looking at other forum posts but they don’t rlly help my case.
local char = script.Parent
local torso = char:WaitForChild("Torso")
local impactSounds = script:WaitForChild("Impact")
local function onTorsoTouched(part)
if part:IsA("BasePart") and not part:IsDescendantOf(char) then
if char:FindFirstChild("Ragdoll") then
local impactSound = impactSounds:GetChildren()[math.random(1, #impactSounds:GetChildren())]
local soundClone = impactSound:Clone()
soundClone.Parent = torso
soundClone.Volume = 1
soundClone.PlaybackSpeed = 1
soundClone:Play()
game.Debris:AddItem(soundClone, soundClone.TimeLength)
end
end
end
torso.Touched:Connect(onTorsoTouched)
local char = script.Parent
local torso = char:WaitForChild("Torso")
local impactSounds = script:WaitForChild("Impact")
local function onTorsoTouched(part)
if script.Parent == game.StarterPlayer.StarterCharacterScripts then return end
if part:IsA("BasePart") and not part:IsDescendantOf(char) and char:FindFirstChild("Ragdoll") then
local impactSound = impactSounds:GetChildren()[math.random(1, #impactSounds:GetChildren())]
local soundClone = impactSound:Clone()
soundClone.Parent = torso
soundClone.Volume = 1
soundClone.PlaybackSpeed = 1
soundClone:Play()
game.Debris:AddItem(soundClone, soundClone.TimeLength)
end
end
torso.Touched:Connect(onTorsoTouched)
Is the actual function running? Try adding some print statements to see where the issue lies.
If the function isn’t even running then the issue is with the .Touched event, and I’m pretty sure that’s the case since .Touched only works with physical movement (which I don’t fully understand yet).
For testing purposes, try making something else trigger the function and see what happens.
yeah, the touch function does run, but i noticed it only runs when the player is actually alive and not in ragdoll
if script.Parent == game.StarterPlayer.StarterCharacterScripts then return end
local char = script.Parent
local torso = char:WaitForChild("Torso")
local impactSounds = script:WaitForChild("Impact")
local function onTorsoTouched(part)
print("Function running")
if part:IsA("BasePart") and not part:IsDescendantOf(char) and char:FindFirstChild("Ragdoll") then
local impactSound = impactSounds:GetChildren()[math.random(1, #impactSounds:GetChildren())]
local soundClone = impactSound:Clone()
soundClone.Parent = torso
soundClone.Volume = 1
soundClone.PlaybackSpeed = 1
soundClone:Play()
game.Debris:AddItem(soundClone, soundClone.TimeLength)
end
end
torso.Touched:Connect(onTorsoTouched)
still nothing, again the function works fine when the player is alive, but not when theyve died. maybe the function cant be called on a dead character? idk
local char = script.Parent
local torso = char:WaitForChild("Torso")
local humanoid=char:WaitForChild("Humanoid")
local impactSounds = script:WaitForChild("Impact")
local function onTorsoTouched(part)
print("Function running")
if part:IsA("BasePart") and not part:IsDescendantOf(char) and humanoid:GetState()==Enum.HumanoidStateType.Dead then
local impactSound = impactSounds:GetChildren()[math.random(1, #impactSounds:GetChildren())]
local soundClone = impactSound:Clone()
soundClone.Parent = torso
soundClone.Volume = 1
soundClone.PlaybackSpeed = 1
soundClone:Play()
game.Debris:AddItem(soundClone, soundClone.TimeLength)
end
end
torso.Touched:Connect(onTorsoTouched)