I’m trying to detect when none of a player’s character parts are touching a brick. Here is my the code I’ve written so far:
local rails = game.Workspace:WaitForChild("Rails")
game.Players.PlayerAdded:Connect(function(plr)
local isTouchingRail = Instance.new("BoolValue")
isTouchingRail.Parent = plr
isTouchingRail.Name = "IsTouchingRail"
isTouchingRail.Value = false
end)
for i, rail in pairs(rails:GetChildren()) do
rail.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player ~= nil then
if player.IsTouchingRail.Value == false then
player.IsTouchingRail.Value = true
end
end
end
end)
end
The problem is now detecting when none of the player’s parts are touching. Simply dectecting when something has stopped touching the part would not work because there’s a chance, for example, when a player’s leg stopped touching the part that another body part is still touching the part. What I want to achieve is detecting when no body parts are touching a brick. How do I achieve this?