I have a piece of code that changes the text in the text-label, which by the way is a bar on top. This works fine but I want for the script, while its changing the text of the textLabel, to check if a part has been touched. Here is the (local) script:

math.randomseed(tick())
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local bar = playerGui:WaitForChild("Bar")
local redDetector = workspace.RedDetector
local blueDetector = workspace.BlueDetector


local RandomSentences = {"How's everyone?",
	"Make sure to leave a like ;)",
	"This is the update bar!",
	"The easiest way to make a goal is with teamwork!",
	"Make sure you have defense!",
	"Buy a VIP server to play with only your friends!"
}


while true do
	wait()
     	bar.TextLabel.Text = RandomSentences[math.random(1,6)]
	wait(100)
end

While the script is running(specifically the while true loop) I want it to check if a part called redDetector or blueDetector(which are in the variables section) have been touched. I dont know if this is an easy add-on or if I need something more advanced like coroutines. Thanks.

4 comments

0

You'll need a touched event.

0

Oh, guys I also forgot to mention. When the part is touched I want the bar to break all the random sentences and say a goal was made.

0

The easiest thing to do would be to wrap your loop in spawn (search it up on the wiki). Then you wouldn't have to worry about where the next piece of code would go

0

do bumps exist on here? if so, bump.