WorldToViewportPoint crashing / pausing game?

Hello!
Im working on a simple FPS game and im having this issue that ive never seen before.

So this is the server script. It handles what happens to bullets then sends information about it to the client. The current part of the project is having Damage Indication System (tells the player how much damage they did).

Events.Shoot.OnServerEvent:Connect(function(plr,part,pos,damage)
	if part.Parent:FindFirstChild("Humanoid") then
		local humanoid = part.Parent.Humanoid
		
		if humanoid.Health > 0 then -- if enemy is alive
			humanoid:TakeDamage(damage)
		end
		print(pos)
		if part.Name == "Head" then
			Events.DIDNumbers:FireClient(plr,
				pos,
				damage,
				"-1"
			)

The local script is as follows

function ClampPosition(CF)
	print(CF)
	local screenPos = cam:WorldToViewportPoint(CF) -- THIS IS WHERE THE WEIRD THING HAPPENS
	local indicatorX = screenPos.X
	local indicatorY = screenPos.Y
	
	indicatorX = clamp(indicatorX, maxX, (gui.AbsoluteSize.X - maxX))
	indicatorY = clamp(indicatorY, maxY, (gui.AbsoluteSize.Y - maxY))
	
	return indicatorX, indicatorY
end

function CreateIndicator(CF,number,numericType) -- Creates the indication for the gui
	print(CF)
	-- Clamp Position
	local indicatorX , indicatorY = ClampPosition(CF)
    -- There is more after this but it should not be needed.


Events.DIDNumbers.OnClientEvent:Connect(CreateIndicator)

So for some reason when it gets to that line in the ClampPosition event it pauses the game. Studio has never paused the game before so I dont know if that means it crashed or something else. When this happens a call stack, breakpoints, and watch window open up. Let me know if you need any more information.

Thanks,

  • Alex

Sounds more like the Lua debugger being enabled more than anything else check for red breakpoints in that script which do the game pausing.

Anyways for this specific line.

It should use

CF.Position instead as it needs a vector3 position value rather than a CFrame.

Found from documentation

https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint

1 Like