How would I detect a player leaving a block if I want something to keep happening while the player is standing on that block. Here is my touch script:
script.Parent.Touched:Connect(function(hit)
hit.Parent .. "touched this block"
end)
How would I detect a player leaving a block if I want something to keep happening while the player is standing on that block. Here is my touch script:
script.Parent.Touched:Connect(function(hit)
hit.Parent .. "touched this block"
end)
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.
1 comment
BasePart.TouchEnded https://developer.roblox.com/api-reference/event/BasePart/TouchEnded