Achievement:
Have a script change a value in ReplicatedStorage whenever a Enemy is added into a folder (using tables).
Issue:
Everytime an enemy dies, it shows this as the error
“Workspace.Scripts.Script:15: invalid argument #2 to ‘remove’ (number expected, got Instance)”.
Attempted Solutions:
Trying to change the amount of time till the Enemy gets destroyed inside of a different script, just changed the Error time
Code:
--// Variables
local Folder = workspace.Enemies
local EnemyTable = {}
local EnemyAmount = game:GetService("ReplicatedStorage").GamePlayFiles.EnemyAmount
--// Adding Enemy
Folder.ChildAdded:Connect(function(enemy)
table.insert(EnemyTable, enemy)
EnemyAmount.Value = #EnemyTable
end)
--// Removing Enemy
Folder.ChildRemoved:Connect(function(enemy)
table.remove(EnemyTable, enemy)
EnemyAmount.Value = #EnemyTable
end)
Thanks to anyone who helped!