Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Touched event isn't detecting players jumping on it?

Asked by 4 years ago

Hello,

How do I achieve the same effect as the tiles on Epic Minigames? Whenever I connect a part to a Touched event and jump on it, it doesn't print anything

Here's a script that connects the Touched event

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        print('test')
    end
end)

The script:

![Image from Gyazo](https://i.gyazo.com/a7babc7ed4477e14d47c9459be0358d4.gif)

The script in Epic Minigames:

![Image from Gyazo](https://i.gyazo.com/643a6f8fbe5ea2070025aa056336058b.gif)

0
This is interesting. I'll look into it in a bit. royaltoe 5144 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

This is a somewhat common issue with the .Touched event as it relies on physics to fire, and physics don't always match from server to client.

A 'hacky' way to fix it would be to have the part to be touched CanCollide = false with another part underneath so that they go through the part that fires the event before being able to jump again.

Another way would be to use Region3 to detect if any part of them is inside the region of the part, but this might be a bit lengthy to complete something as simple as what you're trying to make.

EDIT: I'll keep looking for a better solution and let you know if I find one.

0
you can cast a ray to figure out if the player is jumping on a part. doing a write up on it atm but crappy wifi royaltoe 5144 — 4y
Ad
Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can use raycasting to check if the player is hopping on the part.

I have a working uncopylocked solution here if you want to try it out

I have all the parts that the player can jump on inside of a model.

What the code below is doing is shooting a ray below the character that ends slightly below the player.

If that ray is touching one of the parts in the whitelist (a table containing the parts in the model) then the player is touching that part so it changes the brickcolor.

local ModelContainingParts = script.Parent

function checkIfTouchingPart(player)
    while true do
        wait(.1)
        if player.Character then
            local start = player.Character.HumanoidRootPart.Position
            local lookAt = player.Character.HumanoidRootPart.Position + Vector3.new(0,-5,0)
            local lengthOfRayInStuds = 7

             --the findpartsonray function will find any parts inside this array and only recognize when those parts are touched
            local whiteList = ModelContainingParts:GetChildren() 


            local ray = Ray.new(start, (lookAt-start).Unit * lengthOfRayInStuds)
            local part, position = workspace:FindPartOnRayWithWhitelist(ray, whiteList)

            if part then
                part.BrickColor = BrickColor.Random()
                print("part player is standing/jumping on: ", part)
            end
        end
    end 
end


game.Players.PlayerAdded:Connect(function(player)
    spawn(function() checkIfTouchingPart(player) end)
end)

0
I have tried out this method, but the ray only detects what's under the middle of the HumanoidRootPart. https://gyazo.com/d192fddd37c4f022b70e89551bd31a48 qXlWhitelXp 19 — 4y
0
never thought of that. i can edit it later in the day. royaltoe 5144 — 4y
0
I've edited it and now it's working well, Thank you for your help. qXlWhitelXp 19 — 4y
0
yeah no problem. I think cows way works better sorry I didn't have time to get back to you I had a lot of work over the weekend royaltoe 5144 — 4y

Answer this question