Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

7 comments

0

what is the rest of this script?

0

That's it.

0

cant you do a touched event and a touchended event?

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.

0

If I'm doing if game.Workspace.Part.Touched Can I still find the part that touched it?

0

yes, that is one of the arguments of  the touched event

0

TouchEnded cannot be used like this, it's an event.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.