Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

OnTouched Seat Sound won't work?

Asked by 10 years ago

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

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

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)
0
Thank you xXScorpianKillerXx 25 — 10y
Ad

Answer this question