Should I use Raycast on the Client or Server?

So i am wondering,

Do i cast a Ray on the Client or Server

I have made a Teleporter Tool only using the Client, works on Server
But I made a Weapon using the Server,
It appears to work so I’m just wondering which is better to use.

local RCP = RaycastParams.new()
	RCP.FilterDescendantsInstances = {plr.Character}
	RCP.FilterType = Enum.RaycastFilterType.Blacklist

	local RCR = workspace:Raycast(Tool.Handle.Position, (mousepos - script.Parent.Handle.Position) * 300,RCP)


	if RCR then
		local HP = RCR.Instance
		local model = HP:FindFirstAncestorOfClass("Model")


		if model then
			for _,Humanoid in pairs(model:GetChildren()) do
				if Humanoid.Name == GS.DesiredHumanoid then -- Gets The Name Specified inside the Module Script, if the Name is Equal to that, it will damage the Humanoid
					pcall(function()
						TagHumanoid(Humanoid, plr)
						Humanoid:TakeDamage(GS.Damage)
                         
					end)
				end
			end

		end	

	end
1 Like

It’s entirely circumstantial and dependence on your use-case.
Since it’s not described, I can only infer.

It’s a tool and you’re using raycast for collision detection and calculating damage if true. Never trust the client for operations like this because it can always lie to the server. Since the server will want to distribute the damage anyways, might as well have it raycast too. More secure and easier to troubleshoot.

If you’re damaging something, do raycasts and damage on the server.

If you’re teleporting the player, go ahead, it doesn’t matter as the player already has full physics control.

1 Like

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