So It just supposed to make a bool value true whenever you click a proximity prompt but it not working
In case it to blury here the code:while true do
script.Parent.BrickColor = BrickColor.Random()
wait(0.7)
end
script.Parent.ProximityPrompt.Triggered:Connect(function()
script.Parent.ButtonPressed.Value = true
end)
Im pretty sure to seperate a loop and a function since loops will yield forever (in my understanding)
2 Likes
What bookgamery555gta said.
Also check out this article if it still doesn’t work:
Thank you so much it worked I probably would have thought of that but thank you for just saying that though
1 Like
local part = script.Parent
local prompt = part:WaitForChild("ProximityPrompt")
local buttonPressed = part:WaitForChild("ButtonPressed")
task.spawn(function()
while task.wait(1) do
part.Color = Color3.new(math.random(), math.random(), math.random())
end
end)
prompt.Triggered:Connect(function()
buttonPressed.Value = true
end)
As previously mentioned infinite loops (which never end) will run indefinitely thus the event connection never occurs. I’ve circumvented this issue by wrapping the block of code inside of a call to task.spawn() which creates a new thread, you could alternatively perform the loop after the connection is made.
local part = script.Parent
local prompt = part:WaitForChild("ProximityPrompt")
local buttonPressed = part:WaitForChild("ButtonPressed")
prompt.Triggered:Connect(function()
buttonPressed.Value = true
end)
while task.wait(1) do
part.Color = Color3.new(math.random(), math.random(), math.random())
end