Conditional returning

I’m making a system in my game that returns different values if conditions are met. But it returns absolutely nothing. My main question is, how would I do conditional returns?

function characterStatusManager:StatusCheck(character, hitcharacter: Model, canblock: boolean, canparry: boolean, ragdoll: boolean, ignorespecial: boolean)
	local FStatus = characterStatusManager:RetriveStatus(character)
	local Status = characterStatusManager:RetriveStatus(hitcharacter)
	if Status.Blocking and canblock then
		VFX.CreateSound('rbxassetid://18912884921', 0.2, 1, hitcharacter)
		VFX.Highlight(hitcharacter, Color3.new(0, 0, 1), 0.4)
		return "blocked"
	elseif Status.Blocking and not canblock then
		return true
	end
	if Status.Parrying and canparry then
		VFX.CreateSound('rbxassetid://8132494511', 0.2, 1, character)
		characterStatusManager:Stun(character, 2)
		VFX.Highlight(hitcharacter, Color3.new(1, 1, 0), 0.4)
		return "parried"
	elseif Status.Parrying and not canparry then
		return true
	end
	if Status.Misc and ragdoll then
		return true
	elseif Status.Misc and not ragdoll then
		VFX.Highlight(hitcharacter, Color3.new(0.4, 0.4, 0.4), 0.4)
		return "ragdolled"
	end
	if Status.IFrames then
		return "IFrames"
	end
	if Status.SpecialAction ~= "" and not ignorespecial then
		require(game.ServerScriptService.CombatFramework.SpecialActions).Search(Status.SpecialAction, hitcharacter, character)
		return "special"
	elseif Status.SpecialAction ~= "" and ignorespecial then
		return true
	end
end
1 Like

I think something is causing your code to infinitely yield hence why it’s not returning anything. The way you set up your conditional returns is fine, you just need to find out what’s causing the pause.

EDIT: or if none of your if statements fire you end up going past them all, and you don’t have a return at the end of your function!

1 Like

If the function is not returning anything then none of the if-else blocks have conditions that are being met. Add a return false at the end of your function to ensure that it doesn’t yield (or some other return value that you can use to handle this situation).

How it’s set up is

if blahblahstatus and blahblah then
-- do this and that
elseif blahblahstatus and not blah blah then
return true
end

and then it has another if statement, doin the same thing but different status types.

return true

Is simply just returning true because In the actual CombatHandlingScript I do

local module = require(modulelocation)

for _,hit in hitcontents do
-- pretend theres hitbox handling here
-- if prior conditionals are met then

-- this is just used for move variants, ill just use m1 m2 for arguments sake
if Arg == "M1" then
local HitReturn = module:StatusCheck(char, hitchar, true, true, false)
if HitReturn then
-- handle m1, stun, all of that stuff.
end
end

With all of that explained. I have no Idea what’s stopping it. I will attempt to use a checker to see if nothing in the boxes are being returned or if it’s just trying to run all the ifs at once and I need to make them all One Statement. Since my explaining skills are ABHORABLE, what I mean by One Statement is

if conditionals and canconditional then
-- do this
return -- whatever
elseif conditonals and not canconditional then
-- code
return -- whatever
elseif newconditional and cannewconditional then
-- code
return -- whatever
elseif newconditional and not cannewconditional then
-- code
return -- whatever

Sorry for all the blabbering lol.

If you’re returning inside every “if” or “elseif”, then using either wouldn’t make a difference.

Assuming your code runs on and you are sure its not returning anything rather then just infinitely yielding, use prints to check what the value of the arguments in the if statements are (such as “Status.Blocking”, “canblock”, and “ragdoll”).

1 Like

the issue was, returning true returned nil, so I had to make it a string

1 Like

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