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

Why doesn't my script run when a player is touching the part?

Asked by
Jexpler 63
6 years ago

I want this script to run as long a player is touching it. Why doesn't it run at all?

repeat
    script.Parent.BrickColor = BrickColor.new("Institutional white")
    wait(1)
    script.Parent.BrickColor = BrickColor.new("Really black")
    wait(1)
until script.Parent.TouchEnded
0
what is the rest of this script? theking48989987 2147 — 6y
0
That's it. Jexpler 63 — 6y
0
cant you do a touched event and a touchended event? theking48989987 2147 — 6y
0
Think of it like this, if you have a base plate then the part is calling Touched and Touch Ended event multiple times. Also you need to define the player. RoJiyn 12 — 6y
View all comments (3 more)
0
If I'm doing if game.Workspace.Part.Touched Can I still find the part that touched it? Jexpler 63 — 6y
0
yes, that is one of the arguments of  the touched event theking48989987 2147 — 6y
0
TouchEnded cannot be used like this, it's an event. INOOBE_YT 387 — 6y

1 answer

Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
6 years ago

TouchEnded is an event, not a bool value. You can make it a bool value like this:

local partTouching = nil --The current part touching touch part.
local touchPart = script.Parent --The brick to be used with this script.

touchPart.Touched:connect(function(part)
    partTouching = part --Set the variable to the current touching part.
    repeat
        script.Parent.BrickColor = BrickColor.new("Institutional white")
            wait(1)
        script.Parent.BrickColor = BrickColor.new("Really black")
        wait(1)
    until not partTouching
end)
touchPart.TouchEnded:connect(function(part) --When the touch stops, this event is emitted.
    if part == partTouching then
        partTouching = nil --This part is no longer touching.
    end
end)

If you have any questions or issues, feel free to comment below.

Ad

Answer this question