Cant search dictionary with argument

So im trying to call a function in a dictionary by searching for it with an argument and it isnt working


local StateEffects = {}

local States = {
	
	OnFire = spawn(function(Target, Damage, Duration, Time)
		
		local i = 0
		
		repeat
			
			Target.Character.Humanoid.Health = Target.Character.Humanoid.Health - Damage
			wait(Time)
			i = i + 1
			
		until i == Duration	
		
	end)
	
}	
	
function StateEffects:DealState(Target, State, ...)
	
	local OtherArguments = {...}
	
	States.State(Target, OtherArguments)
	
end

return StateEffects

its giving me an error - Attempt to call a nil value at line 26 (thats the line 4th line in DealState function)

That’s not how dictionary work States.State is a sugar syntax for States["State"], use States[State] instead.

1 Like

If you want to index a dictionary by a variable, use square brackets. States[State](...)
Aiya, @Blockzez beat me to it :stuck_out_tongue:

Im still getting the same error

You still need to make sure that State will always be a key in the States dictionary. As far as I can tell, the only State that exists is “OnFire,” and that one isn’t even a callable function, rather a thread.

how could i make it a callable function?

Your OnFire definition refers to a thread which is returned by the spawn() function; Just remove the spawn, then OnFire would refer to a function that you could call.

1 Like

thanks that actually worked :+1: :+1: :+1: