Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Local script playing sound for everyone in the server?

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

✓ Accepted answer

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)

1 comment

0

Thank you so much! It works now

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.