#trying to get part to change color every time it's touched but only in intervals of 2 seconds
1 messages · Page 1 of 1 (latest)
this starts a new, separate loop every time the part is touched
add a debounce variable
what exactly do you want the script to do?
everytime it's touched just to have it change in intervals of like 1-2 seconds
not give u epilepsy
so with a 2 second cooldown?
or change every 2 seconds
so like touch -> color change -> wait -> touch -> color change -> rpeeat
either could work right? preferably change color every 2 seconds though
like theyd have the same effect?
no that's different
in programming you tell the computer exactly what to do
so it could either be that the part changes color when it's touched
and if it's touched after less than 2 seconds it does nothing
and after that it doesn't change color until it's touched again
This could kill someone!!!!
or it could be that it's touched and it changes color every 2 seconds forever
ohhh
** You are now Level 2! **
i can't tell what you want
Epilepsy attacks are no joke
i didnt realize that this was what it would do i see
the desired effect is that when you touch it it changes color but the color only changes every 2 seconds and like
if you leave it be it remains @ that same color
@bleak plinth stop ❌ reacting me
local stimSphere = script.Parent
local debounce = false
stimSphere.Touched:Connect(function(hit)
if debounce then
return
end
stimSphere.BrickColor = BrickColor.random()
debounce = true
task.wait(2)
debounce = false
end)
so here you make a variable named debounce
whats a debounce?
when the part is touched, debounce is set to true
while it's set to true, if it's touched then it exits the code block using return
and then after 2 seconds it's set to false again
cooldown basically
and if it's false, the code block isn't exited and the part changes color
its just a variable to keep track of whether you can change colour again
alr thx yall this is very helpful i'll mess around w/this more & close the thread
Why did bro make it sound so complicated? Its a fucking debounce bro
well it's important to know what your code is doing
instead of copy pasting from tutorials
mindlessly
Yeah, but no need to explain the it returns if it is true and then it is ser to false after .2 seconds or whatever cooldown ur talking abt
You have to add print(“cool”)
** You are now Level 1! **
btw im pretty sure using .Random is better
idk the logic behind it but I’ve heard it is
for someone who already does scripting it's intuitive but for someone new it may not be
why are u complaining about someone explaining code 😂
what’s so bad about explaining what each line does
But I aint a nerd that says «umm acually🤓 it sets the variable to tru wich returns it later if clicked»