I’m a newish scripter, and I’m trying to make a sound for when you’re inside a transparent part. I need it to be very accurate as when I tested it, a person can have a arm sticking into a wall, and activating the sound like this.
--//Services
local Players = game:GetService("Players")
--//Variables
local Part = workspace.Part
local Sound = Part.Sound
--//Functions
Part.Touched:Connect(function(hit)
--//Checks if the part hit isn't named Torso and isn't named HumanoidRootPart
if hit.Name ~= "Torso" and hit.Name ~= "HumanoidRootPart" then
--//If so, return
return
end
--//Finds the player
local Player = Players:GetPlayerFromCharacter(hit.Parent)
--//If there isn't a player, return
if not Player then
return
end
--//Play the sound
Sound:Play()
end)
--//Services
local Players = game:GetService("Players")
--//Variables
local Part = workspace.Part
local Sound = Part.Sound
--//Functions
Part.Touched:Connect(function(hit)
--//Checks if the part hit isn't named Torso and isn't named HumanoidRootPart
if hit.Name ~= "Torso" and hit.Name ~= "HumanoidRootPart" then
--//If so, return
return
end
--//Finds the player
local Player = Players:GetPlayerFromCharacter(hit.Parent)
--//If there isn't a player, return
if not Player then
return
end
--//Play the sound
Sound:Play()
end)
Part.TouchEnded:Connect(function(hit)
--//Checks if the part's that hit ended isn't named Torso and isn't named HumanoidRootPart
if hit.Name ~= "Torso" and hit.Name ~= "HumanoidRootPart" then
--//If so, return
return
end
--//Finds the player
local Player = Players:GetPlayerFromCharacter(hit.Parent)
--//If there isn't a player, return
if not Player then
return
end
--//Stop the sound
Sound:Stop()
end)