#Color bugs
100 messages · Page 1 of 1 (latest)
Im gonna assume ur problem is that it does that even when you dont touch it
** You are now Level 3! **
You need to check if humanoid is there
yeah this script works fine what's wrong
he did
he is walking on it
mb for not responding the bug is its not going in a patern
Oh
like every 0.1 sec the next color
u want it to go on forever?
and there is a useless for loop here
the for loop does nothing
How odd i do it
** You are now Level 5! **
Just add a while wait() do inside if plr
Like?
can u copy and paste the script here?
Yep
You need a debounce. That, or disconnect your function from the event after you've verified a player collided with the BasePart
Note that BasePart.Touched is not an event that responds to player collisions, but pure collisions between BaseParts. If anything "Plr" would be a reference to a player's limb
So what should i do
first of all what do you even want to do, you want it to change colors again and again forever?
Yes
copy paste the script here
local Bp = game.Workspace.Baseplate
script.Parent.Touched:Connect(function(Plr)
if Plr then
while wait() do
script here
wait(0.1)
end
end
end)
Thx
and add a wait(0.1) at the end
just do while task.wait(0.1) do ;-;
Still bugs
show the script
local Part = script.Parent
local Baseplate = workspace.Baseplate
local Debounce = false
Part.Touched:Connect(function(Hit)
if Debounce or not Hit.Parent:FindFirstChild("Humanoid") then return end
Debounce = true
while task.wait(0.1) do
Baseplate.BrickColor = BrickColor.random() -- Replace this with your code
end
end)
Disconnect the function
its gonna go on forever anyway
And your function is still going to be fired as a consequence of the event
There's no point in keeping a "dead" function in an event call stack
hmmm
Also, it's considered a bad practice to use task.wait in boolean logic
wym
You should instead write:
while true do
-- ...
task.wait(0.1)
end
huh, whats the difference
^
it worked thanks
how would I do that?
local connection = Part.Touched:Connect(function(Hit)
-- blah blah
end)
connection:Disconnect()
like that?
There's no difference but it's bad practice to do while wait
Yes
there is a while true do in the function tho
it wont go after that would it
I dont need any help anymore but thanks
right but we are discussing smthn else ;P
local connection
connection = basePart.Touched:Connect(otherPart: BasePart)
-- Post confirmation of player collision
connection:Disconnect()
-- ...
end)
what im saying is would it even disconnect? there is a while true do loop
huh I did try that, it doesnt work
oh wait
nvm
I did local connection = basepart.Touched
I get it
local Part = script.Parent
local Baseplate = workspace.Baseplate
local Debounce = false
local Connection : RBXScriptConnection
Connection = Part.Touched:Connect(function(Hit)
if Debounce or not Hit.Parent:FindFirstChild("Humanoid") then Connection:Disconnect() return end
Debounce = true
while task.wait(0.1) do
Baseplate.BrickColor = BrickColor.random() -- Replace this with your code
end
end)
so like this?
disconnect only works on connections (:connect(function())
it just stops that code from running again
I never really use disconnect tbh I just let the dead connections be, I do realise its a bad pactice but um.. yea
thats not what I meant
I get it now tho
nvm it
Absolutely. All that RBXScriptSignal:Connect does is store your given function reference into an array. When the game engine invokes an event, the event invokes the functions stored inside it with related arguments. The functions are executed in a separate thread as to not interrupt any internal logic, especially not to lock up the other connected functions as prior ones complete execution. Disconnecting your function removes it from that array, preventing it from being called as a product of the event any longer
Because your function is now designed to only run once, you can get rid of the debounce
oo I see
o alr
Mhm. What I did is called "forward declaration". The "connection" variables needs to be accessible by the function as it is held accountable for regulating the number of times it runs in response to the event. In your case, you defined the function at the same time you defined the overall expression result to be equal to the returned RBXScriptConnection object. Because the variable won't "exist" until your expression is evaluated, the function involved in the expression won't be aware of the variable
ye I realised 2 seconds after seeing ur script, I just never thought of it
It's basically like trying to do:
x = 1 + x
Yeah it was needed
For the touched event
It is needed 👀
Not needed, you could of disabled CanTouch once it was touched and enabled it
after a certain amount of time
but
a connection
works
UNLESS
he wants it to work
only once
then disabling cantouch is very much useless
Also, Jesus Christ, @gleaming relic
I just noticed you created 500 event listeners
What the hell's with that? 👁️👄👁️
what the frick
It's a perpetual loop, so...
once it was touched, keyword. It requires a connection for the .Touched event.
