Im using a localscript:
game.Players.PlayerAdded:connect(function(player) sound = Instance.new("Sound",player.PlayerGui)
sound.SoundId = "rbxassetid://12222005"
part = game.Workspace.Music canplay = true
function muziekspelen(otherpart)
local humanoid = otherpart.Parent.Humanoid if humanoid and canplay then sound:Play() canplay = false sound.Looped = true print(otherpart) end
end
canplay = true end) part.Touched:connect(muziekspelen)
Your part.Touched event is not triggering because of how you positioned it inside your script. Don't have it inside your Players.PlayerAdded event.
EDIT:
Your sound was not being copied to the PlayerGui because the server cannot access it due to how FilteringEnabled works. You would have to use RemoteEvents or RemoteFunctions for that. Lucky for you there's no need for that in your case: just manually put your sound inside StarterGui in studio.
However you will still need to have a RemoteEvent call FireClient() when your part gets pressed, then have a LocalScript play your sound:
Inside a regular script:
local part = game.Workspace.Music local RemoteEvent = Instance.new("RemoteEvent", part) canplay = true local function muziekspelen(otherpart) print(otherpart) local humanoid = otherpart.Parent:FindFirstChild("Humanoid") if humanoid and canplay then local player = game.Players:GetPlayerFromCharacter(otherpart.Parent) canplay = false RemoteEvent:FireClient(player) end canplay = true end part.Touched:connect(muziekspelen)
Inside a local script inside StarterGui:
local RemoteEvent = game.Workspace:WaitForChild("Music"):WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer RemoteEvent.OnClientEvent:Connect(function() local sound = player.PlayerGui:WaitForChild("sound") sound:Play() sound.Looped = true print(otherpart) end)
game.Players.PlayerAdded:connect(function(player) sound = Instance.new("Sound",player.PlayerGui) sound.SoundId = "rbxassetid://12222005" local part = game.Workspace.Music canplay = true local function muziekspelen(otherpart) print(otherpart) local humanoid = otherpart.Parent.Humanoid if humanoid and canplay then sound:Play() canplay = false sound.Looped = true print(otherpart) end end canplay = true part.Touched:connect(muziekspelen) end)
It doesn't give any errors anymore, but it still doesn't play the sound