A return statement completely stops function

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

  1. What do you want to achieve? Keep it simple and clear!
    To pass through the if statement without the rest of the script below it stopping

  2. What is the issue? Include screenshots / videos if possible!
    When I return the if statement it completely stops the script and doesn’t pass through the rest of it

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked around the forum and haven’t found anything, I also looked through the rest of my scripts and haven’t found anything that should be interfering with it

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local function OnPlayerAdded(player:Player)
	Inputs.InputTable[player] = {}
	
	if DataManager:Get(player, "FirstName") == "N/A" then
		NameSelector.LoadUI(player)
	end	
	
	if DataManager:Get(player, "Race") == "Shinigami" then
		local Profile = DataManager:GetProfile(player)
		
		if not Profile.Data["ShikaiElement"] then
			warn("Setting ShikaiElement")
			Profile.Data["ShikaiElement"] = "Snow"
		else
			return
		end
	end
	
	player.CharacterAdded:Connect(function(character: Model) 
		local Humanoid = character:FindFirstChild("Humanoid")
		character:SetAttribute("Attacking", false)
		character:SetAttribute("Blocking", false)
		character:SetAttribute("Stunned", false)
		character:SetAttribute("InCombat", false)
		
		CharacterHandler:LoadCharacterAppearance(player)	
		task.wait()
		Humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
		Humanoid.HealthDisplayDistance = 0
		Humanoid.DisplayName = tostring(DataManager:Get(player, "FirstName") .. " " .. DataManager:Get(player, "LastName"))
		Humanoid.NameDisplayDistance = 12.5
	end)
	
	player:LoadCharacter()
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I’ve used print functions throughout to see where it stops

if DataManager:Get(player, “Race”) == “Shinigami” then
local Profile = DataManager:GetProfile(player)

	if not Profile.Data["ShikaiElement"] then
		warn("Setting ShikaiElement")
		Profile.Data["ShikaiElement"] = "Snow"


	else
		return -- stops right after return
	end
end

Just remove it. A return statement terminates whatever thread it’s in

1 Like

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