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?

1repeat
2    script.Parent.BrickColor = BrickColor.new("Institutional white")
3    wait(1)
4    script.Parent.BrickColor = BrickColor.new("Really black")
5    wait(1)
6until 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:

01local partTouching = nil --The current part touching touch part.
02local touchPart = script.Parent --The brick to be used with this script.
03 
04touchPart.Touched:connect(function(part)
05    partTouching = part --Set the variable to the current touching part.
06    repeat
07        script.Parent.BrickColor = BrickColor.new("Institutional white")
08            wait(1)
09        script.Parent.BrickColor = BrickColor.new("Really black")
10        wait(1)
11    until not partTouching
12end)
13touchPart.TouchEnded:connect(function(part) --When the touch stops, this event is emitted.
14    if part == partTouching then
15        partTouching = nil --This part is no longer touching.
16    end
17end)

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

Ad

Answer this question