I tried making a cool rising/lowering platform based on whether players are standing on it. But in touch detection, if my character stops moving the touch defaults to “touch ended”
its like, enter platform → “hey touch began!” → still standing on platform but stop moving → “hey touch ended!” (what?!) and yeah this is a problem.
I tried making a custom hitbox, and i tried every touch method out there (touched/touchEnded, getTouchingParts, getPartsInPart) and all are the same.
local function makeSinkingObject(part)
local hitbox = part.Parent:WaitForChild("Hitbox") -- part.Parent is the parent model
game:GetService("RunService").Heartbeat:Connect(function()
for i,v in ipairs(workspace:GetPartsInPart(hitbox)) do
if v.Parent:FindFirstChild("Humanoid") then
print("detected humanoid")
else
print("no humanoids")
end
end
end)
end
if you had this problem or know Anything, please reply. I could use all the help, there were no forum posts about this…
youre honestly a lifesaver. Its irrelevant which part/model you detect, but you made me think “wait, am i detecting other parts?” and realized I was also detecting the Hitbox 247 lol. Thats why it printed “not humanoid” half the time, you really made my day just now
Update, heres the solution. Theres actually 2 parts to this.
First, detecting characters without using a hitbox is bad, because characters are actually located 0.1 studs above ground
Second, when detecting with a Hitbox, constant touch detection works perfectly. You just need to add OverlapParams to GetPartsInPart, and filter the original platform from detection.
Heres the finalized code i made up, it prints the amount of parts touching the Hitbox
local hitbox = object.Parent:WaitForChild("Hitbox")
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = object.Parent:GetDescendants()
overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
game:GetService("RunService").Heartbeat:Connect(function()
local parts = workspace:GetPartsInPart(object, overlapParams)
print(#parts)
end)
Another code snippet here for detecting if a Humanoid is touching the Hitbox
local hitbox = object.Parent:WaitForChild("Hitbox")
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = object.Parent:GetDescendants()
overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
game:GetService("RunService").Heartbeat:Connect(function()
for i,v in ipairs(workspace:GetPartsInPart(object, overlapParams)) do
if v.Parent:FindFirstChild("Humanoid") then
print("humanoid")
end
end
end)