Calling module function in one thread inserts the same table

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I’ve been making projectile engine module where script can pass properties into module to create projectile that simulates physics and other stuff

  2. What is the issue?
    When passing properties in single thread example: shotgun fires 6 bullets, but when it passes through the engine one bullet simulates but 6x faster while the rest is frozen in place

  3. What solutions have you tried so far?
    I’ve been looking at how to separate function, self and other stuff but i couldn’t find solution as i could not find with one thread function passing same table in module.

-- Server script (example)
local pro = require(script.Projectilee)
	for i=1,4 do
        -- // 4 different bullets
		pro.fire({i})
	end
 -- Module
local list = {}

engine.fire = function(set)
local bullet = Instance.new("Part")
set[2] = bullet -- // it should be different in new fire function
table.insert(list,set)
print(list) -- // each table should have different part, and number
end

I started using modules recently to ease up development and been figuring out with shared source and difference, but i’ve been dealing with this problem 2 days ago.

Can you show the Projectile module cuz the root cause prolly lies there.


more example of problem when fire function is fired second time in one lua thread
simple version :
1 projectile fired, inserted into table, after half second fires another projectile, but the data is the same as first projectile inserted into table, but the instance is the same, even if set[11] is set by new projectile it did not change once inserted

I figured out how to fix this, somehow it loads the same table with same instance but creating new table inside function prevents this, and fixes the problem

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