hello, i have recently been working on a sound system for a train and one of these features is a script that goes inside a part, which when a player enters plays a different set of sounds for the inside. however if the player sits in a seat im starts playing the exterior sounds, which i do not want. i have tried looking into touchended alternatives as i believe that is the cause however most rely on a set area or are quite complicated to understand.
i have a video showing the problem
heres the code (this would be put into a client based script inside the trigger part)
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Parent.Parent.Parent.exterior.HVAC.sound.Playing = false
script.Parent.Parent.Parent.exterior.underframe.idle.Playing = false
script.Parent.Parent.Parent.interior.airconint.idle.Playing = true
script.Parent.Parent.Parent.interior.presreg1.idle.Playing = true
script.Parent.Parent.Parent.interior.presreg2.idle.Playing = true
script.Parent.Parent.Parent.interior.compressor.Sound.Playing = true
end
end)
part.TouchEnded:Connect(function(hitend)
script.Parent.Parent.Parent.exterior.HVAC.sound.Playing = true
script.Parent.Parent.Parent.exterior.underframe.idle.Playing = true
script.Parent.Parent.Parent.interior.airconint.idle.Playing = false
script.Parent.Parent.Parent.interior.presreg1.idle.Playing = false
script.Parent.Parent.Parent.interior.presreg2.idle.Playing = false
script.Parent.Parent.Parent.interior.compressor.Sound.Playing = false
end)```
Ok so I know this is very late but here’s the solution, You simply check in the Touchended function if the humanoid is sitting or not, if the humanoid is sitting then you want to skip the touchended function, for that to work you must first set a value that tells if the humanoid is sitting or not
Here it is implemented with your script:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Parent.Parent.Parent.exterior.HVAC.sound.Playing = false
script.Parent.Parent.Parent.exterior.underframe.idle.Playing = false
script.Parent.Parent.Parent.interior.airconint.idle.Playing = true
script.Parent.Parent.Parent.interior.presreg1.idle.Playing = true
script.Parent.Parent.Parent.interior.presreg2.idle.Playing = true
script.Parent.Parent.Parent.interior.compressor.Sound.Playing = true
end
end)
humanoid.Seated:Connect(function(active)
if active then IsSeated = true else IsSeated = false end
end)
part.TouchEnded:Connect(function(hitend)
script.Parent.Parent.Parent.exterior.HVAC.sound.Playing = true
script.Parent.Parent.Parent.exterior.underframe.idle.Playing = true
script.Parent.Parent.Parent.interior.airconint.idle.Playing = false
script.Parent.Parent.Parent.interior.presreg1.idle.Playing = false
script.Parent.Parent.Parent.interior.presreg2.idle.Playing = false
script.Parent.Parent.Parent.interior.compressor.Sound.Playing = false
end)