Im trying to request a function from the module script but its not working and im getting this error:
16:44:30.903 Workspace.Conveyor.Script:3: attempt to index nil with ‘SpawnRandomItem’ - Server - Script:3
16:44:30.904 Stack Begin - Studio
16:44:30.904 Script ‘Workspace.Conveyor.Script’, Line 3 - Studio - Script:3
16:44:30.904 Stack End - Studio
16:44:31.029 Players.TheReal_MrMonkey.PlayerScripts.LocalScript:22: Expected identifier when parsing expression, got ‘local’ - Studio - LocalScript:22
16:44:34.618 Disconnect from 127.0.0.1|58617 - Studio
Here is the script requesting the funciton
local module = unpack(require(game.ServerScriptService["Dough Spawning"]))
local SpawnLocation = script.Parent.SpawnPart
local SpawnDough = module.SpawnRandomItem()
while true do
wait(0.2)
SpawnDough(SpawnLocation)
end
local module = require(game.ServerScriptService["Dough Spawning"])
local SpawnLocation = script.Parent.SpawnPart
local SpawnDough = module.SpawnRandomItem
while true do
wait(0.2)
SpawnDough(SpawnLocation)
end
17:28:45.408 Players.TheReal_MrMonkey.PlayerScripts.LocalScript:22: Expected identifier when parsing expression, got 'local' - Studio - LocalScript:22
17:28:46.381 Workspace.Conveyor.Script:7: attempt to call a nil value - Server - Script:7
17:28:46.381 Stack Begin - Studio
17:28:46.381 Script 'Workspace.Conveyor.Script', Line 7 - Studio - Script:7
17:28:46.381 Stack End - Studio
local SpawnModule = {}
local ItemStorage = game.ReplicatedStorage.Dough -- Folder containing your items
local ItemChances = {
-- ItemName = Weight
["Chimpanzni"] = 50,
}
local LuckModifier = 1
function SpawnRandomItem(SpawnLocation)
local TotalWeight = 0
for _, weight in pairs(ItemChances) do
TotalWeight = TotalWeight + weight
end
local AdjustedTotalWeight = TotalWeight / LuckModifier
local RandomRoll = math.random(1,AdjustedTotalWeight)
local CurrentWeight = 0
local ChosenItemName = nil
for ItemName, Weight in pairs(ItemChances) do
CurrentWeight = CurrentWeight + Weight
if RandomRoll <= CurrentWeight then
ChosenItemName = ItemName
break
end
end
if ChosenItemName then
local ItemToClone = ItemStorage:FindFirstChild(ChosenItemName)
if ItemToClone then
local ClonedItem = ItemToClone:Clone()
ClonedItem.CFrame = SpawnLocation.CFrame
ClonedItem.Parent = workspace
print("Spawned: " .. ChosenItemName)
end
else
warn("No item chosen!")
end
end
return SpawnModule
function SpawnModule.SpawnRandomItem(SpawnLocation)
local TotalWeight = 0
for _, weight in pairs(ItemChances) do
TotalWeight = TotalWeight + weight
end
local AdjustedTotalWeight = TotalWeight / LuckModifier
local RandomRoll = math.random(1,AdjustedTotalWeight)
local CurrentWeight = 0
local ChosenItemName = nil
for ItemName, Weight in pairs(ItemChances) do
CurrentWeight = CurrentWeight + Weight
if RandomRoll <= CurrentWeight then
ChosenItemName = ItemName
break
end
end
if ChosenItemName then
local ItemToClone = ItemStorage:FindFirstChild(ChosenItemName)
if ItemToClone then
local ClonedItem = ItemToClone:Clone()
ClonedItem.CFrame = SpawnLocation.CFrame
ClonedItem.Parent = workspace
print("Spawned: " .. ChosenItemName)
end
else
warn("No item chosen!")
end