Module script infinite yield

So basically I want to make a nuke, where only 2 players can have the nuke keys at the same time, for that I am using a module script to count how many keys have been picked up, now the issue is, that it yields infinite for no reason:

ModuleScript (ibmkey):

local keys = { keys = 0 }

return keys

The Script responsible for giving out keys:

local detector = script.Parent.ClickDetector
local serverstorage = game:WaitForChild("ServerStorage")

detector.MouseClick:Connect(function(x)
	local imbkey = game.ServerScriptService:WaitForChild("ibmkey")
	local ibmkeys = imbkey:WaitForChild("keys")
	local launchkey = serverstorage:WaitForChild("IBM Launch Key"):Clone()
	if ibmkeys == 2 then
		return
	end
	launchkey.Parent = x.Backpack
end)

Output:

  15:47:36.907  Infinite yield possible on 'ServerScriptService.ibmkey:WaitForChild("keys")'  -  Studio
  15:47:36.907  Stack Begin  -  Studio
  15:47:36.908  Script 'Workspace.TestingParts.Part.Script', Line 6  -  Studio - Script:6
  15:47:36.908  Stack End  -  Studio
  15:47:48.130  Disconnect from ::ffff:127.0.0.1|58706  -  Studio

It looks like you are attempting to get a child of the module script, but this only works for instances and will give you either nil or a table of instances, maybe just try this

local imbkey = require(game.ServerScriptService:WaitForChild("ibmkey"))
local ibmkeys = imbkey.keys

Oh yep, that definitely works, now I am gonna test it and increment the key count and see if it works!

Does incrementing the key work?

Yes, you have to increment the key manually, like this:

imbkey.keys = imbkeys.keys + 1

instead of doing this

you can do this

imbkey.keys += 1
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.