Function never calles and script won't continue

I’ve been working on my custom handles (You can see my first post :wink:). As the title says, I call a function and it never fires and the script won’t continue. I will do my best to show you where the problem happens.

 	game.Players.LocalPlayer:GetMouse().Move:Connect(function()
        local _,Data,Pos = data.IsMouseInRay()
        if Data and Data.Object then
           LastData = Data
		end
		if InUse and typeof(Data) == "nil" and data.LastInRay and UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
			local succes,err = pcall(function()
				local Pos2D = GetSpaceVector(Data.Id) -- This function won't fire and the next code won't work

				if LastType == LastData.Id then
					LastPosition = GetPosition((Pos-LastData.Object.Position),Data.Id)
					MouseDrag:Fire(LastData.Id,LastPosition)
				elseif LastType ~= LastData.Id then
					LastType = LastData.Id
					LastPosition = GetPosition((Pos-LastData.Object.Position),Data.Id)
				end
			end)
		elseif InUse and UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) and LastData then
           local succes,err = pcall(function()
           if LastType == LastData.Id then
               LastPosition = GetPosition((Pos-LastData.Object.Position),Data.Id)
               MouseDrag:Fire(LastData.Id,LastPosition)
            elseif LastType ~= LastData.Id then
               LastType = LastData.Id
               LastPosition = GetPosition((Pos-LastData.Object.Position),Data.Id)
           end
			end)
		end
	end)

There are no errors.

I’m just testing GetSpaceVector so it doesn’t return anything, but it is a print in it that never gets called.

If you want to check GetSpaceVector then this is the code:

local GetSpaceVector = function(Space)
		warn(typeof(Space)) -- The warn never gets called
		--local IsFound,DataObject,Pos = data.IsMouseInRay() 
		local PosGot
	end

pcall absorbs errors so it won’t show in the output, this includes your warn statement in the function. If there’s an error, you wrote local success, err so err would hold the error message. You should check that at the end of your if statement to see what went wrong.

1 Like

Make sure there isn’t anything yielding the thread the code would be running in (i.e. a loop, coroutine, etc.). You may also find it helpful to use print statements to narrow down where exactly your code doesn’t continue.

You should also consider tralalah’s reply:

pcall absorbs errors so it won’t show in the output, this includes your warn statement in the function. If there’s an error, you wrote local success, err so err would hold the error message. You should check that at the end of your if statement to see what went wrong.

Oh yeah :sweat_smile: I forgot about it. Thanks anyways, the problem was I put in the elseif typeof(Data) == “nil”

1 Like