Ad
Log in to vote
1

Local script playing sound for everyone in the server?

Asked by 2 months 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:

local part = game.Workspace.elevatorsong
part.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    spawn(function()
        wait(0)
        game.Workspace.elevatorsong.CanTouch = false
        game.Workspace.elevsongg.elevsong:Play()
        wait(31.88)
        game.Workspace.elevatorsong.CanTouch = true
    end)
end)

2 answers

Log in to vote
1
Answered by 2 months 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.

local part = game.Workspace.elevatorsongpart
local song = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("elevatorsong")
local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
part.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    if hit.Parent == character then
        spawn(function()
            wait(0)
            part.CanTouch = false
            song:Play()
            song.Stopped:Wait()
            part.CanTouch = true
        end)
    end
end)
0
Thank you so much! It works now hellmet1 42 — 2mo
Ad
Log in to vote
0
Answered by 2 months ago
local part = game.Workspace.elevatorsongpart
local song = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("elevsongg"):WaitForChild("elevatorsong")
part.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    spawn(function()
        wait(0)
        part.CanTouch = false
        song:Play()
        song.Stopped:Wait()
        part.CanTouch = true
    end)
end)

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