I don’t know how to make it so if the local player touches a part, only they can hear it, but know one else can hear it unless the touch the same part. Do you think this code would work?
local Part = script.Parent
local Sound = Part.Sound
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild:("Humanoid") then
Sound:Play()
end
If I were to make the script a local script, would it work?
If you want the local player to hear a sound after a part is touched it would look something like this
--Inside a local script
local PartToTouch = workspace.Part
local debounce = false
local Sound = game.ReplicatedStorage.Sound
PartToTouch.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if debounce then return end
debounce = true
Sound:Play()
wait(Sound.TimeLength)
debounce = false
end
end)
the best solution would involve using a remote event, but the easiest is just to do a playercheck in the localscript
local Part = somewhere.Part
local Sound = Part.Sound
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") == nil then return end
if game.Players:GetPlayerFromCharacter(Hit.Parent) ~= game.Players.LocalPlayer then
return
end
Sound:Play()
end)