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.
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.
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
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
yes it does
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
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.
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.