Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a sound play without part.Touched?

Hello so i have this script:

local sound = script.Sound

function onTouched(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
		if h ~= nil then
			wait(4)
			sound:Play()
		end
end

function onTouchEnded(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
		if h ~= nil then
		sound:Stop()
		end
end

script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(onTouchEnded)

and it works fine. but the problem is that when i move it sometimes stops playing. any help? region3 might be helpful but i don't want to make a new part. i want it to be existing and used for the script.

thanks!

2 comments

0

try capitalizing the f in "findFirstChild"

0

also, if it is a local script the touched event will not work

1 answer

local sound = script.Sound

function onTouched(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
        if h then -- You don't need to check for nil, just make sure that h is satisfied.
            wait(4)
            sound:Play()
        end
end

function onTouchEnded(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
       if h then
        sound:Stop()
        end
end

script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(onTouchEnded)

1 comment

0

still broken

This discussion is preserved as it was. New answers, comments, and votes are closed.