Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I keep getting an error when I try to run my coroutine?

I just figured out how to use coroutines, so I made a little script that levels you up to 1 when your exp changes to anything higher than 0.

BUT I get this error: Workspace.Script:14: attempt to call upvalue 'level' (a thread value) , and I don't know why..

Here's the script:

local level = coroutine.create(function(level) level.Value = level.Value + 1 end)


game.Players.PlayerAdded:connect(function(plr)
	local lvl = Instance.new("IntValue", plr)
	lvl.Name = "Level"
	lvl.Value = 0
	
	local expx = Instance.new("IntValue", plr)
	expx.Name = "Exp"
	expx.Value = 0	
	
	expx.Changed:connect(function()
		coroutine.resume(level(lvl))
	end)
end)

2 answers

You defined the coroutine with the variable level. You then proceeded to make the coroutine take parameters under the variable level. Try changing one or the other and it should work

This is not an appropriate use of a coroutine. Just use functions.

function increase(obj)
	obj.Value = obj.Value + 1
end

-- ...

	expx.Changed:connect(function()
		increase( lvl )
	end)

1 comment

0

yeah, i just wanted to try it out xd

This discussion is preserved as it was. New answers, comments, and votes are closed.