For some reason I can not call w()
I am trying to call w() at line 79
w() Creates the 3D object local part. At line 66 it does a pcall and goes to the pages named in info at line 3 Then a few lines down it waits five seconds tweens back in the page. Then it opens back up the menu, however it does not make the 3D object...
w() should create that object.
Is it because I can't call coroutine twice? If so what should I do?
I just took a look at my code, if you notice at line 51 it sets it up and does rotation.
Should I just make that a function and apply it to line 79?
My script
wait() local handler = require(script.Parent:WaitForChild("Module3D")) local info = {{game.Lighting.Tools.Cube,"Play"};{game.Lighting.Tools.Coin,"Statistics"};{game.Lighting.Tools.Hat,"Catalog"};{game.Lighting.Tools.Wrench,"Options"}} --Add more info here! moe = info[1] model = moe[1] current = 1 local frame = script.Parent.Holder.ItemFrame --Item Location activeModel = handler:Attach3D(frame,model) last = model local Confirm = script.Parent.Holder.Confirm w = coroutine.wrap( function() while wait() do if script.Parent.Parent.Parent.Character:WaitForChild("Humanoid").Health <=0 then activeModel:End() end if model ~= last then activeModel:End() activeModel = handler:Attach3D(frame,model) script.Parent.Holder.ItemName.Text = moe[2] game:GetService("RunService").RenderStepped:connect(function() -- 60 FPS local fullRotation = math.pi*2 --360 degrees in radians local currentRotation = tick()%fullRotation activeModel:SetActive(true) activeModel:SetCFrame(CFrame.Angles(0,currentRotation,0)) end) last = model end model = moe[1] end end ) w() script.Parent.Holder.Next.MouseButton1Click:connect(function() if current < #info then current = current+1 moe = info[current] else current = 1 moe = info[current] end end) script.Parent.Holder.Back.MouseButton1Click:connect(function() if current == 1 then current = #info moe = info[current] else current = current - 1 moe = info[current] end end) --Rotate! :D game:GetService("RunService").RenderStepped:connect(function() -- 60 FPS local fullRotation = math.pi*2 --360 degrees in radians local currentRotation = tick()%fullRotation activeModel:SetActive(true) activeModel:SetCFrame(CFrame.Angles(0,currentRotation,0)) end) --Confirms the selection Confirm.MouseButton1Down:connect(function() --Do checking for what is selected. script.Parent.Holder.Visible = false activeModel:End() if not pcall(function()script.Parent[moe[2]].Visible = true script.Parent[moe[2]]:TweenPosition(UDim2.new(0.167, 0, 0.347, 0), "Out", "Quad", 1, "false") wait(5) script.Parent[moe[2]]:TweenPosition(UDim2.new(-0.666, 0, 0.347, 0), "In", "Quad", 1, "false") wait(1) script.Parent[moe[2]].Visible = false script.Parent.Holder.Visible = true w() --Why can't I call you!? Why are you nil? o.o end) then else end end) --Check if player has died script.Parent.Parent.Parent.Character:WaitForChild("Humanoid").Died:connect(function() --Thank you SamuelKingx activeModel:End() end)
A single coroutine cannot be resume
d twice.
Instead, define your w
(I strongly recommend a better name) as another wrapper function, like this:
function makeObject() coroutine.wrap( funct... ...end)(); end
This will create a new coroutine each time you call it, and run (resume) it.