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

Help with a touch script? :)

Asked by
Nidoxs 190
10 years ago

I want someone to touch the 'trigger' then a new sound is made and put in the players StarterGui so it plays only for them, but I don't want the sound to play another time for the player,I only want it to play once then the brick can identify who has gone through and who hasn't so the sound can't play a second time! I would like to have a debounce in it aswell, but I don't understand how to do it? Here is what I have so far:

function onTouched(Part) 
    local SoundMaker = Instance.new("Sound", game.StarterGui) 
    SoundMaker.SoundId = ("http://www.roblox.com/asset/?id = 156637449")
    local Sound = game.StarterGui.Sound
    Sound:Play()
end

Much appreciated if anyone can help? :)

2 answers

Log in to vote
1
Answered by 10 years ago

Okay, there's many errors here. You can copy and paste the full script below, and you can remove the comments if you'd like:

db = false --Debounce variable. False means the function will run and true means the function won't run.

function onTouched(Part)
    if db then return end --If db is true, then stop the function.
    db = true --Set db to true so the function can't be repeated while it's true.
    if Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then --If there is a Humanoid in the model and a player is found then...
        local plr = game.Players:GetPlayerFromCharacter(Part.Parent) --The player which is found.
        if plr.PlayerGui:FindFirstChild("onTouchSound") then return end
        local sound = Instance.new("Sound", plr.PlayerGui) --Make the sound
        sound.Name = "onTouchSound"
        sound.SoundId = "http://www.roblox.com/asset/?id=156637449" --No need for spaces in the SoundId
        sound:Play() --Play the sound
    end
    wait(2) --Change to how long you want the debounce delay to be.
    db = false --Sets db to false so the function can run again.
end

script.Parent.Touched:connect(onTouched)
0
16:44:48.336 - Workspace.Part.Script:9: ')' expected (to close '(' at line 1) near '<eof>' Nidoxs 190 — 10y
0
Wait the sound is playing! Nidoxs 190 — 10y
Ad
Log in to vote
-3
Answered by
Relatch 550 Moderation Voter
10 years ago
script.Parent.Touched:connect(function(hit)
    local SoundMaker = Instance.new("Sound", game.StarterGui) 
    SoundMaker.SoundId = ("http://www.roblox.com/asset/?id = 156637449")
    local Sound = game.StarterGui.Sound
    Sound:Play()
    Sound.Parent = hit.Parent
end

0
Why thumbs down? I edited it. Relatch 550 — 10y
1
I hear no sound. But thanks for helping! Nidoxs 190 — 10y
0
No need to thumbs down twice. Jesus christ. Relatch 550 — 10y
0
If the answer you've given isn't useful, people are going to down vote it. Spongocardo 1991 — 10y
0
This works, its just I want to know how to only make it play one time. christiandaepic 0 — 6y

Answer this question