ONLY ISSUE: I don’t know how to make the function call without an ERROR
I know I’m just using the coroutines wrong here so someone can probably give me a quick solution I hope. I literally couldn’t find a single decent example of someone doing this WITH arguments in the function I know it should be really simple.
local paddleFlash = coroutine.create(function(pad,transp)
local oTime = time()
pad.Transparency = 0.25
while true do
task.wait()
local cTime = time()
local dt = cTime - oTime
print(dt)
pad.Transparency = pad.Transparency + (dt*0.2)
if pad.Transparency >= transp then
pad.Transparency = transp
break
end
end
end)
local function ComputerHitBall()
coroutine.resume(paddleFlash(PCPad,PCPad.Transparency))
end
What you’re doing here is trying to call paddleFlash and then trying to use coroutine on the result.
This is how you should use arguments with coroutines:
I’m not actually sure. I think you need to create a new coroutine each time:
local function paddleFlash(pad,transp)
pad.Transparency = 0.25
while true do
local dt = task.wait()
print(dt)
pad.Transparency = pad.Transparency + (dt*0.2)
if pad.Transparency >= transp then
pad.Transparency = transp
break
end
end
end
local function ComputerHitBall()
coroutine.resume(coroutine.create(paddleFlash), PCPad, PCPad.Transparency)
end
Also I modified the dt variable for testing because for some reason cTime - oTime kept giving me 0 on my computer.
That is WEIRD what’s even WEIRDER is when I try your method of making the coroutine each time the function gets called every time, BUT now the while true do loop never runs! So it just stops before???
update fixed via this:
local function ComputerHitBall()
local co = coroutine.create(function()
paddleFlash(PCPad,PCPad.Transparency)
end)
coroutine.resume(co)
end