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

Local script playing sound for everyone in the server?

Asked by 2 years ago

So, i made a localscript that plays a sound after touching a part, but it plays the sound for everyone, and i made a local script just because i wanted it to do that. Here's the script:

01local part = game.Workspace.elevatorsong
02part.Touched:Connect(function(hit)
03    if not hit.Parent:FindFirstChild("Humanoid") then return end
04    spawn(function()
05        wait(0)
06        game.Workspace.elevatorsong.CanTouch = false
07        game.Workspace.elevsongg.elevsong:Play()
08        wait(31.88)
09        game.Workspace.elevatorsong.CanTouch = true
10    end)
11end)

2 answers

Log in to vote
1
Answered by 2 years ago

Ok LAST post because I know this works. I know this works because I tested it with my brother in the game.

The local script should be in StarterPlayerScripts. The sound should be in PlayerGui. And the part should be in workspace.

01local part = game.Workspace.elevatorsongpart
02local song = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("elevatorsong")
03local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
04part.Touched:Connect(function(hit)
05    if not hit.Parent:FindFirstChild("Humanoid") then return end
06    if hit.Parent == character then
07        spawn(function()
08            wait(0)
09            part.CanTouch = false
10            song:Play()
11            song.Stopped:Wait()
12            part.CanTouch = true
13        end)
14    end
15end)
0
Thank you so much! It works now hellmet1 42 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
01local part = game.Workspace.elevatorsongpart
02local song = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("elevsongg"):WaitForChild("elevatorsong")
03part.Touched:Connect(function(hit)
04    if not hit.Parent:FindFirstChild("Humanoid") then return end
05    spawn(function()
06        wait(0)
07        part.CanTouch = false
08        song:Play()
09        song.Stopped:Wait()
10        part.CanTouch = true
11    end)
12end)

also changed some names so that it's less confusing, also, the song is inside of a model, that's why there's elevsongg and elevatorsong, but the model only has the sound in it so it's okay.

Answer this question