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

How do I make it so that when a player touches a Part that music plays?

Asked by 10 years ago

I am a novice at Lua & Scripting, Could anyone help me?

3 answers

Log in to vote
4
Answered by
Bubby4j 231 Moderation Voter
10 years ago
local sound = script.Parent.Sound --The sound object to play

script.Parent.Touched:connect(function(p) --When the parent part is touched
    local human = game.Players:GetPlayerFromCharacter(p.Parent) --Check touching part is part of a Player character
    if human and not sound.IsPlaying then --If player and the sound isn't already playing
        sound:Play() --Play the sound
    end
end)

Be sure to name the sound/music Sound, or to edit the script with the name.

Both the script & sound should be inside the part.

Ad
Log in to vote
0
Answered by 5 years ago

try this

script.Parent.Touched:Connect(function(c)
game.Workspace.Sound:Play()
0
Add a end) at it DogHouseForMe 0 — 5y
Log in to vote
0
Answered by 4 years ago

thanks for attending the ted talk

Answer this question