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

How make a player touch a part it play sound?

Asked by 4 years ago

Hello im try to make a scanner thing, so i try to make player touch it play sound wait 3 seconds then repeat the process script:

Touched:connect(function(player) script.Parent.Sound:Play()

end

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

So what I'm assuming is you want a sound to play whenever a player touches and repeat it twice?

script.Parent.Touched:Connect(function(player) --When the part is touched connect to a function
    local hit = player.Parent:FindFirstChild("Humanoid") --Find the player's character
    local db = false --Create a debounce
    if hit then --If the object that touched it is a player then
        if not db then
            script.Parent.Sound:Play() --Play the sound
            sound.Ended:Wait() --Wait for the sound to end
            wait(3)
            script.Parent.Sound:Play()
            sound.Ended:Wait()
            db = true
        end
    end
end)

Put this in a LocalScript. If you want it to play for everyone or for certain people then learn about RemoteEvent here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

0
Thanks superplayer1453 -4 — 4y
Ad

Answer this question