Created
September 10, 2023 02:28
-
-
Save topherPedersen/dae28e2f8af1bb1340c4cc53aa64f100 to your computer and use it in GitHub Desktop.
Detect Collisions Between Humanoids in Roblox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- DisplayTextModule is some code I use to display text on screen for testing, if you see this in a code snippet, ignore this part | |
local DisplayTextModule = require(script.Parent.Parent.StarterGui.ScreenGui.Frame.TextLabel.DisplayTextModuleScript) | |
local Players = game:GetService("Players") | |
-- Works for R15, not sure if this works for R6 or not | |
local function partIsHumanoid(part) | |
if part.Name == "Head" then | |
return true | |
elseif part.Name == "UpperTorso" then | |
return true | |
elseif part.Name == "LowerTorso" then | |
return true | |
elseif part.Name == "LeftFoot" then | |
return true | |
elseif part.Name == "LeftLowerLeg" then | |
return true | |
elseif part.Name == "LeftUpperLeg" then | |
return true | |
elseif part.Name == "RightFoot" then | |
return true | |
elseif part.Name == "RightLowerLeg" then | |
return true | |
elseif part.Name == "RightUpperLeg" then | |
return true | |
elseif part.Name == "LeftHand" then | |
return true | |
elseif part.Name == "LeftLowerArm" then | |
return true | |
elseif part.Name == "LeftUpperArm" then | |
return true | |
elseif part.Name == "RightHand" then | |
return true | |
elseif part.Name == "RightLowerArm" then | |
return true | |
elseif part.Name == "RightUpperArm" then | |
return true | |
else | |
return false | |
end | |
end | |
local function onPlayerAdded(player) | |
local character = player.Character or player.CharacterAdded:Wait() | |
local humanoid = character:WaitForChild("Humanoid") | |
humanoid.Touched:Connect(function(otherPart) | |
local timestampStr = tostring(os.time(os.date("!*t"))) | |
if partIsHumanoid(otherPart) then | |
DisplayTextModule.Display("Collision w/ R15: " .. otherPart.Name) | |
end | |
end) | |
end | |
Players.PlayerAdded:Connect(onPlayerAdded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment