✓ Accepted answer
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)
3 comments
It does exist in the workspace btw
can you put your code in a codeblock correctly?
please accept my answer if it helped you