Someone Knows why this script is crashing the game?
function Droppers:Init(tycoon)
coroutine.wrap(function()
while true do
task.wait(Rate)
Droppers:Drop()
end
end)()
end
function Droppers:Drop(tycoon)
local CollectionService = game:GetService("CollectionService")
for i, Dropper in pairs(CollectionService:GetTagged("Dropper")) do
Rate = Dropper:GetAttribute("Rate")
local Type = Dropper:GetAttribute("Type")
for _, Drop in pairs(CollectionService:GetTagged("Drop")) do
local Type2 = Drop:GetAttribute("Type")
if Type == Type2 then
local Cdrop = Drop:Clone()
Cdrop.Parent = Dropper
Cdrop.Position = Dropper.Dropper.Pos.Position
end
end
end
return Rate
end
When âwhile true doâ loops donât have a wait ,the game crashes because itâs trying to do something an infinite amount of times in an Instance.
There doesnât seem to be a reference or variable to the âRateâ in the first function so it probably didnât count it as a wait , have you tried replacing it with a number and see what happens?
Yea if Rate donât have a pre-declared value before you run Droppers:Drop() it will crash due to it running an infinite amount of time. Plus Droppers:Drop doesnât even changes Rate since there are no variable for the returning parameter.
Do this:
function Droppers:Init(tycoon)
coroutine.wrap(function()
while true do
DropperRate = Droppers:Drop() --since Rate is already a pre-existing variable.
task.wait(DropperRate)
end
end)()
end
Maybe itâs a problem with the script who calls the module?
local Tycoon = require(game:GetService("ServerScriptService").General)
local doro = script.Parent.Doro
local text = script.Parent.Parent.BillboardGui.TextLabel
local EFteam = game:GetService("Teams")["Explosive Flash"]
local Buttons = require(game:GetService("ServerScriptService").Components.Buttons)
local EFtycoon = game:GetService("ServerStorage").Tycoons["Explosive Flash"]
local db = false
local EFwtyccon = script.Parent.Parent
local Owner = EFwtyccon:GetAttribute("Owner")
local Droppers = require(game:GetService("ServerScriptService").Components.Droppers)
Tycoon.new(EFwtyccon)
doro.CanCollide = false
doro.Touched:Connect(function(player)
Tycoon:Init(player,doro, text,EFteam,EFwtyccon)
Buttons:New(EFwtyccon)
if doro.Parent.Parent:GetAttribute("Owner") ~= nil
then
EFwtyccon:SetAttribute("Owner",true)
Buttons:Init("1buttonEF", EFwtyccon.Purchables)
Droppers:new(EFwtyccon)
Droppers:Init(EFwtyccon)
Buttons:Buy1(EFwtyccon)
Buttons:Buy2(EFwtyccon)
doro.CanTouch = false
end
end)
Iâm not seeing any glaring mistakes there with your function calls. Again, you could try verifying their type using a typechecker?
Similar to:
--!strict
local Tycoon : Model = ...
local doro : BasePart = ...
local text : TextLabel = ..
-- etc.
See what you end up with!
Should add that a typechecker in LuaU will accomplish something similar to assert(), where it will throw an error (if in !strict mode if a variable isnât of a certain class.
So itâll be an issue with your corotuine then. A thread essentially is a line of execution, coroutines are temporarily second threads that return to the main program.
For some reason, your script believes that youâre trying to call a coroutine instead of a function.
2:
Type-checking allows you to track variables by class when assigning and passing to functions, like so:
local myVar : Class = ...
-- A script would be
local myScript : Script = script
-- If the script was a child of a part
local myPart : BasePart = script.Parent
-- For functions
local function(arg1 : BasePart, arg2 : Model)
print(type(arg1), type(arg2))
end
That script wasnât working so I gave up and make another but now it doesnât doesnât crash immediately but create many droops ignoring the wait (I put a wait on the while script) and without being at the position I want, you know howcan I fix this?
function Droppers:Drop(tycoon)
local CollectionService = game:GetService("CollectionService")
for _, Dropper in pairs(CollectionService:GetTagged("Dropper")) do
for _, Drop in pairs(CollectionService:GetTagged("Drop")) do
local Type = Dropper:GetAttribute("Type")
local Type2 = Drop:GetAttribute("Type")
local Rate = Dropper:GetAttribute("Rate")
if Type == Type2 and Dropper:IsDescendantOf(workspace) then
wait(Rate)
local Cdrop = Drop:Clone()
Cdrop.Position = Dropper.Dropper.Pos.Position
Cdrop.Parent = Dropper.Parent
end
end
end
end