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

Script that makes a block play a sound when you touch it, but works only once?

Asked by 7 years ago
Edited 7 years ago

How do I make a script that plays a sound when you touch the block but the next time you touch the block it doesn't play the sound?

2 answers

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

Assuming you know some stuff I wrote this script. So what this does is when a part is touched it will check if it was touched by a player and then play the sound. The script checks if the sound is playing already so it doesn't glitch. Then it waits and destroys the script so it can't run again.

local part = script.Parent --player will touch the parent of this script
local sound = script.Parent:WaitForChild("NameOfYourSound") --the sound is inside the part

part.Touched:connect(function(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    if human then
        if sound.IsPlaying == false then
            sound:Play()
            wait(time of sound)
            script:Destroy()
        end
    end
end)
0
Honestly, we don't like to asnwer these questions. Mainly because its a non-attempt and they haven't shown anything they have tried. H4X0MSYT 536 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Is this it?

local NotTouched = true
local Object = (insert part object here)
local Sound = (insert sound object here)
Object:Touched:connect(function(hit)
if hit == game.Players.LocalPlayer.Character.Humanoid and NotTouched then
NotTouched = false
Sound:Play()
end
end)
Object:TouchEnded:connect(function(hit)
if hit == game.Players.LocalPlayer.Character.Humanoid and NotTouched then
Sound:Stop()
end
end)

Answer this question