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

The part.TouchEnded function doesnt work properly, any solutions?

Asked by
Galicate 106
5 years ago

Here's my script. I tried using if Part:GetTouchingParts() ~= nil but that didnt work to well as it wouldnt fire if there were no parts touching it to fire the event.

script.Parent.MeshPart1.Touched:Connect(function(Part)
    script.Parent.MeshPart1.BrickColor = BrickColor.new("Really red")
    script.Parent.MeshPart2.BrickColor = BrickColor.new("Really red")
    script.Parent.MeshPart3.BrickColor = BrickColor.new("Really red")
end)

script.Parent.MeshPart1.TouchEnded:Connect(function(Part)
    script.Parent.MeshPart1.BrickColor = BrickColor.new("Deep blue")
    script.Parent.MeshPart2.BrickColor = BrickColor.new("Deep blue")
    script.Parent.MeshPart3.BrickColor = BrickColor.new("Deep blue")
end)

I couldn't really find any non laggy uncomplicated ways that dont involve things such as while true loops etc.

0
note that gettouchingparts only returns baseparts that are literally intersecting the part's boundaries. that is, only a part inside another part will be included in the table. simply touching the surface does not count Gey4Jesus69 2705 — 5y
0
diy TheluaBanana 946 — 5y

1 answer

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

TouchEnded is only really useful for when a player walks through a large invisible part. I think if you made an invisible part the player had to walk through, and it was fairly thick, then you could set it up so while the player is inside that area touching it, the brick would stay that color, and when they stop touching or walk out of the area, the TouchEnded event would trigger. I personally hate using TouchEnded and it needs to be fixed in my opinion. Anyways, your script will work if you basically just make a thick hitbox the player walks through.

Here's an example of what I mean, just do yours with an invisible hitbox and instead of printing text, have it change the color, and your script is currently setup to pretty much do that. https://imgur.com/a/XQKfO

Try this with that method:

local touching = false

script.Parent.MeshPart1.Touched:Connect(function(Part)
    if touching == false then
        script.Parent.MeshPart1.BrickColor = BrickColor.new("Really red")
        script.Parent.MeshPart2.BrickColor = BrickColor.new("Really red")
        script.Parent.MeshPart3.BrickColor = BrickColor.new("Really red")
        touching = true
    end
end)

script.Parent.MeshPart1.TouchEnded:Connect(function(Part)
    if touching == true then
        script.Parent.MeshPart1.BrickColor = BrickColor.new("Deep blue")
        script.Parent.MeshPart2.BrickColor = BrickColor.new("Deep blue")
        script.Parent.MeshPart3.BrickColor = BrickColor.new("Deep blue")
        touching = false
    end
end)
Ad

Answer this question