#Color bugs

100 messages · Page 1 of 1 (latest)

gleaming relic
#

When I do the script for some reason they all bug to form

dark brook
#

seems normal

pure oar
woven cedarBOT
#

studio** You are now Level 3! **studio

pure oar
#

You need to check if humanoid is there

tacit kelp
dark brook
#

he is walking on it

gleaming relic
pure oar
#

Oh

gleaming relic
#

like every 0.1 sec the next color

dark brook
#

and there is a useless for loop here

dark brook
gleaming relic
#

How odd i do it

woven cedarBOT
#

studio** You are now Level 5! **studio

pure oar
gleaming relic
#

Like?

pure oar
#

can u copy and paste the script here?

gleaming relic
#

Yep

placid frost
#

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

gleaming relic
#

So what should i do

dark brook
gleaming relic
#

Yes

dark brook
pure oar
#
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)
gleaming relic
#

Thx

pure oar
dark brook
gleaming relic
#

Still bugs

dark brook
gleaming relic
dark brook
#
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)
dark brook
placid frost
#

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

dark brook
#

hmmm

placid frost
#

Also, it's considered a bad practice to use task.wait in boolean logic

placid frost
#

You should instead write:

while true do
    -- ...

    task.wait(0.1)
end
dark brook
gleaming relic
#

it worked thanks

dark brook
#

like that?

tacit kelp
dark brook
#

it wont go after that would it

tacit kelp
#

No

#

You should put all connections before any while true loops

gleaming relic
#

I dont need any help anymore but thanks

dark brook
placid frost
dark brook
dark brook
#

oh wait

#

nvm

#

I did local connection = basepart.Touched

#

I get it

dark brook
# placid frost ```lua local connection connection = basePart.Touched:Connect(otherPart: BasePa...
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?

tacit kelp
dark brook
#

I never really use disconnect tbh I just let the dead connections be, I do realise its a bad pactice but um.. yea

dark brook
#

I get it now tho

#

nvm it

placid frost
# dark brook what im saying is would it even disconnect? there is a while true do loop

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

placid frost
placid frost
# dark brook nvm it

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

dark brook
placid frost
#

It's basically like trying to do:

x = 1 + x
dark brook
#

All of this needed a simple fix

#

Not even a Connection was needed for this

tacit kelp
#

For the touched event

placid frost
dark brook
#

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

placid frost
#

Also, Jesus Christ, @gleaming relic

#

I just noticed you created 500 event listeners

#

What the hell's with that? 👁️👄👁️

dark brook
#

what the frick

placid frost
dark brook
#

.....

#

thats basically doing while true do instance.new("Part", workspace) end

tacit kelp