I am a novice at Lua & Scripting, Could anyone help me?
1 | local sound = script.Parent.Sound --The sound object to play |
2 |
3 | script.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 |
8 | 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.
try this
1 | script.Parent.Touched:Connect( function (c) |
2 | game.Workspace.Sound:Play() |