Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to detect a player not touching a block anymore?

1 answer

You can detect when a player is no longer touching a block by using the .Touched event.

An example would be:

local part = script.Parent;
local Players = game:GetService("Players");

part.Touched:Connect ( function (hit)
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid");
	if humanoid then
		local player = Players:GetPlayerFromCharacter(hit.Parent); 
		print(player.Name, "is touching the part");
	end
end)

part.TouchEnded:Connect ( function (hit)
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid");
	if humanoid then
		local player = Players:GetPlayerFromCharacter(hit.Parent);
		print(player.Name, "is no longer touching the part");
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.