Jumping fires a TouchEnded signal for no reason

robloxapp-20230623-1234453.wmv (1.1 MB)

Here is the only script in the red block:

script.Parent.TouchEnded:Connect(function()
	script.Parent.Transparency = 0
	wait(.1)
	script.Parent.Transparency = .5
end)

Why does the block run this script when I jump in it? I didn’t stop touching the red block when I jumped.

I believe this has to do with how roblox checks what is touching and what isn’t by checking if anything is touching one of the faces and not if there is something inside. You can simply fix this by using the touched event and the workspace:getpartsinpart() function.

Edit: use an if statement to check if once the part isn’t being touched anymore then check how many part are in it and if it is more than 0 then do not call this function.

1 Like

Better but a bit advanced solution is using raycasts and runservice.
But I agree that :GetPartsInPart() is a better option than Touch events.

You would still have to use the touched event as the getpartsinpart() is a function and not an event so you would have to use both.

1 Like

Yeah ik, I just said that the regular touch event sucks and implying getpartsinpart() improves it

1 Like

Ah ok thanks for clarifying that.

1 Like

Also by the way, I don’t know if you can understand how this modul works but i’m gonna mention it, ForeverHD made an amazing modul that works like Touch and TouchEnded but is much more better and accurate.

You can find the link to the post here: link

Even though you’re still touching the block from a player’s perspective, there might be moments during jumping when the character’s hitbox is not in contact with the block. This could be due to a slight gap that might occur during the jumping animation, even if it’s just for a fraction of a second.

local Humanoid = script.Parent:FindFirstChild("Humanoid")
local RootPart = script.Parent:FindFirstChild("HumanoidRootPart")
local Block = game.Workspace:FindFirstChild("Block")
local RayLength = 3 -- The length of the raycast. Adjust as needed.

local function CheckIfOnBlock()
    local RayOrigin = RootPart.Position
    local RayDirection = Vector3.new(0, -RayLength, 0)
    local RaycastParams = RaycastParams.new()
    RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist
    RaycastParams.FilterDescendantsInstances = {script.Parent} -- Prevents ray from detecting the player itself
    local Ray = workspace:Raycast(RayOrigin, RayDirection, RaycastParams)
    
    if Ray and Ray.Instance == Block then
        return true
    else
        return false
    end
end

Humanoid.Jumping:Connect(function()
    wait(0.1) -- Waits a moment to see if player has really stopped touching the block
    if not CheckIfOnBlock() then
        script.Parent.Transparency = 0
        wait(.1)
        script.Parent.Transparency = .5
    end
end)