Whenever any part of my character touches any part in the workspace, I want it to return that part I touched. I also want it in a local script. How?
I feel like when you use .Touched in a localscript, it only detects the character touches already, but I’m unsure.
Otherwise you can loop through the player’s bodyparts like so:
for _, v in pairs(character:GetChildren()) do
if v:IsA("BasePart") then
-- you can insert the touched event for 'v' here, it'll work for all the player's bodyparts
end
end
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local debounce = false
for _, part in ipairs(character:GetChildren()) do
if part:IsA("BasePart") then
part.Touched:Connect(function(hit)
if debounce then
return
end
if hit.Parent.Name == player.Name then --ignore if character parts are touching eachother
return
end
debounce = true
print(player.Name.." touched "..hit.Name.."!")
task.wait(2) --cooldown
debounce = false
end)
end
end
Local script inside StarterCharacterScripts folder.