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 11 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
11 years ago
1local sound = script.Parent.Sound --The sound object to play
2 
3script.Parent.Touched:connect(function(p) --When the parent part is touched
4    local human = game.Players:GetPlayerFromCharacter(p.Parent) --Check touching part is part of a Player character
5    if human and not sound.IsPlaying then --If player and the sound isn't already playing
6        sound:Play() --Play the sound
7    end
8end)

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 6 years ago

try this

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

thanks for attending the ted talk

Answer this question