Client's "mouse" cannot see SetNetworkOwner(nil) parts

I am rewriting my own game’s scripts, and now want to use SetNetworkOwner(nil) on a character. The thing is, when hovering on the character it should show it’s name with health.

But this simply does not work. When I try to use raycasts and hover over character, it does not print name of character but instead what’s behind it. Same happens when I use Mouse.Target.

Any ideas? I’ve tried duplicating bodyparts of character for clients and setting SetNetworkOwner to auto for them, but this just breaks everything.

1 Like

Setting the network owner to the server shouldn’t make the part invisible to players. Can you check if the part has CanQuery on?

1 Like

Weirdly CanQuery is on, and if I place “v.CanQuery = true” nothing changes. By the way, part is visible for players, just not for raycasts and mouse.Targets, but I need to find a way to somehow detect hovering over model and a way to create ClickDetectors in them.

What about your FilterDescendantsInstances? If your raycasting and the model is a child of whatever you put within the filter it will get ignored

I didn’t really touch FilterDescendantsInstances and my original code uses mouse.Target. Ty for assistance by the way!

Can you at least post the code so we don’t have to keep guessing?

Raycasting code

local Camera = workspace.Camera
local UserInputService = game:GetService("UserInputService")

local function raycast()
	local ViewportSize = Camera.ViewportSize
	local MousePosition = UserInputService:GetMouseLocation()
	local reference = Camera:ViewportPointToRay(MousePosition.X, MousePosition.Y)
	return workspace:Raycast(reference.Origin, reference.Direction * 999)
end

while true do
	local rayc = raycast()
	if rayc.Instance then
		print(raycast().Instance)
	end
	task.wait(1)
end

That’s because you’re calling the function again. Why don’t u just print rayc.Instance?

wb this?

local Camera = workspace.Camera
local UserInputService = game:GetService("UserInputService")

local function raycast()
	local ViewportSize = Camera.ViewportSize
	local MousePosition = UserInputService:GetMouseLocation()
	local reference = Camera:ViewportPointToRay(MousePosition.X, MousePosition.Y)
	return workspace:Raycast(reference.Origin, reference.Direction * 999)
end

while true do
	local rayc = raycast()
	if rayc then
		print(rayc.Instance)
	end
	task.wait(1)
end

At the end I fixed my issue with setting networkownership only to HumanoidRootPart of character and not each bodypart. Thanks everyone for help!

network ownership doesn’t do anything :skull:
Did this work before or after we told you to stop recalling the function?

yes it does :skull:
My original code used mouse.Target and it worked before I used setnetworkowner(nil). When you told me to stop recalling function it did not change anything. Only after I stopped looping through all bodyparts to setnetworkowner(nil). Setting networkownership to nil is also very essential to my game.

It’s good to hear it worked but I self-tested this on parts that have their network ownership on the server and to a player. The results? The raycast detected both parts regardless of their network ownership. Network ownership just dictates who will be calculating a part’s physics

I don’t believe setting the any of the character’s parts to server ownership is good practice. (not sure)

as this could cause latency and unnecessary server load

No idea why it didn’t work for me until I used HumanoidRootPart. Maybe because I used character with bodymover and bodyorientation inserted.

Unfortunately, without setting networkowner to nil the character lags after reaching specific checkpoint, and also exploiters just can mess with character to delete it and unfairly recieve rewards.

Then you need to validate from the server, and it’d have latency issues if you were to set the character to nil (the server)

1 Like

TO CLARIFY:

Steve over here is not setting a player’s character’s ownership. He is setting the networkownership of an “enemy” in a tower defense game.

If an exploiter gains networkownership of this enemy, they can do just about anything to it and it would replicate to the server, and as a result EVERYONE INGAME; kill it, cframe it to the void, or manipulate its movement.

The purpose of setting networkowner to nil was to prevent this altogether, however there were some issues with the mouse not recognizing the enemy anymore. This has been solved now.

Ah, I didn’t realize he was talking about a enemy in a tower defense game. He just said “character” so I assumed he was talking about the player’s character.

1 Like

Yeah, that’s why I had to clarify. Sorry about this!