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

OnTouched Seat Sound won't work?

I am trying to make a Script play a Sound when you sit on the Seat, but it will not work.

function onTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
local pl = game.Players:GetPlayerFromCharacter(hit.Parent)
wait()
I = Instance.new("Sound",Workspace)
I.SoundId = "http://www.roblox.com/asset/?id=142435510"
I.Volume = 0.7
I.Pitch = 1
end
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

It's better to check for a weld using ChildAdded, because you don't always sit when you touch a sit brick.

local sp = script.Parent

sp.ChildAdded:connect(function(weld)
	I = Instance.new("Sound", Workspace)
	I.SoundId = "http://www.roblox.com/asset/?id=142435510"
	I.Volume = 0.7
	I.Pitch = 1
	I:Play()
	while true do 
		if not sp:findFirstChild(weld.Name) then 
			I:Stop()
			I:Destroy()
			break
		end
		wait()
	end
end)

1 comment

0

Thank you

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