How inneficient is this method of handling my problem

  1. What do you want to achieve? I need every character to have values that are constantly changing during gameplay.

  2. What is the issue? I’m not sure how i should structure this system.

  3. What solutions have you tried so far? I tried making a Table inside modules script. And everytime a character was added, a second table for that specific character would be created in that initial table.
    ex: ModuleTable = {player1 = {}, player2 = {}}
    This worked for a while, but i ran into problems. Mainly due to the fact that i can’t detect changes made to a table (like a .Changed event) and because you can’t have multiple items of the same name in a table.

The new way i thought of doing this is by having this script in ReplicatedStorage:
imagem_2023-10-14_041008947

CharacterAdded:Connect(function(Character)
	local clone = script.InfoFolder:Clone()
	clone.Parent = Character
end)

Whenever i want an attack to be on cooldown, i add an BoolValue with the attack’s name to the Cooldowns folder, and then add it to debris with the duration of the attack

local Table = {["boolean"] = "BoolValue", ["number"] = "NumberValue", ["string"] = "StringValue"}

AddInstance = function(Name, Value, Parent, Lifespan)
	-- This creates an instance with the type of value given
	local NewValue = Instance.new(Table[typeof(Value)])
	-- Ex: if Value is a "boolean" then it will create a "BoolValue"
	NewValue.Name = Name
	NewValue.Value = Value
		
	Debris:AddItem(NewValue, Lifespan)

	NewValue.Parent = Parent

end
-- In another script
local Cooldown = Character.InfoFolder.Cooldowns:FindFirstChild(Attackname)
if not Cooldown then
	-- Attackscript
end

How bad is this bad for performance? It’s the only way that worked for me.

I’m not exactly sure how the exact effect this will have on performance but

you can use this method. To replicate the behavior of a value, you can use a bindable event and/or a remote event.

local changedEvent = path to bindableevent

changedEvent.Event:Fire() -- run when you change a value

-- somewhere else

local changedEvent = path to bindableevent

changedEvent:Connect(function()
	
end)

You can have a bindable under an easily accessible place and a different script can connect to it.

You can use an array to circumvent this as well.

1 Like