Else firing when first condition is true

So I’m trying to make the base of a request system where one player can accept the other’s request if they don’t have one going.

The thing is that when I check if the invited player already has a request going or not, both if and else are fired.

Here’s the relevant part of the code:

--[[ Local Script ]]

function requestHandler(invitedPlayer)	
	if invitedPlayer ~= localPlayer then
		UpdateRequestStats:FireServer()
			
		MainFrame:TweenPosition(UDim2.new(.5, 0, .5, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1)
		RequestQuestion.Text = "Send a Battle Request to "..invitedPlayer.Name.."?"
			
		local function onAcceptance()
			MainFrame:TweenPosition(UDim2.new(.5, 0, -1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1)
			StatsLabel.Visible = true
			
			if GetPlayerRequestStats:InvokeServer(invitedPlayer) ==  false then -- checking if the player has a request going
				-- Send Battle Request to that player
				SendRequest:FireServer(invitedPlayer)
				StatsLabel.Text = "Waiting for response..."
			else -- but this block of code is being fired too
				StatsLabel.Text = invitedPlayer.Name.." already has a request going."
				wait(2)
				StatsLabel.Visible = false
				StatsLabel.Text = ""
			end
		end	
		YesButton.MouseButton1Click:Connect(onAcceptance)
	end
end

--[[ Server Script ]]

UpdateRequestStats.OnServerEvent:Connect(function(player)
	
	local playerFolder = ServerStorage:FindFirstChild(player.Name)
	
	if playerFolder then
		local hasRequest = playerFolder:FindFirstChild('HasRequest')
		
		if hasRequest then
			hasRequest.Value = not hasRequest.Value
		end
	end
end)

GetPlayerRequestStats.OnServerInvoke = function(invitedPlayer)
	local playerFolder = ServerStorage:FindFirstChild(invitedPlayer.Name)
	
	if playerFolder then
		local hasRequest = playerFolder:FindFirstChild('HasRequest')
		
		if hasRequest then
			return hasRequest.Value
		end
	end
	return nil
end

If someone could spot my mistake, I’ll thank you a lot!

1 Like

GetPlayerRequestStats:InvokeServer(invitedPlayer)

Try localizing the return value of this and comparing that instead.

What i mean:

local result = GetPlayerRequestStats:InvokeServer(invitedPlayer)
if not result then
else
end
1 Like