Hi devs,
Is there a way to set the network owner of a part that behaves like it’s anchored?
Hi devs,
Is there a way to set the network owner of a part that behaves like it’s anchored?
The network ownership of anchored parts is the server. If you want to set their network ownership you’ll need to make them unanchored first.
There isn’t a point to worry about network ownership on an anchored-like part since there’s no physics involved, what exactly are you trying to achieve? There might be better ways to get there.
A bit of a necro, but this is an issue that’s been annoying me for a while now. So I’ll leave this hacky workaround if anyone else wants it.
@httpDerpyy
Being able to set network ownership on anchored parts has quite a few benefits. Let’s say you have a custom character system (not using anything built-in like Player.Character). You could create and set the character up on the server, then let the client take it over and unanchor it at any point you want without the server’s involvement. That way you get a much more reliable character loading system if you want non standard (non-Humanoid characters).
Right now, the only way to achieve anything similar would be to temporarily disable collisions and unanchor the part on the server. Wait for a frame with task.wait() (because the part is considered a sleeping/anchored part until the next physics cycle), and set the network ownership. At the same time, fire a remote telling the client that they now own the part, also sending the part’s last anchored position. Then have the client reanchor the part and set CanCollide back to true.
This workaround is… questionable at best as replication for Anchored is a bit weird. It only replicates to the clients, so the server thinks it’s still unanchored, but not moving.
Here’s a couple of sample scripts as an example.
-- Script with RunContext set to Server
local client = game:GetService("Players").PlayerAdded:Wait();
task.wait(5);
print("Starting");
local part = script.Parent;
local cf = part.CFrame;
local couldcollide = part.CanCollide;
part.Anchored = false;
part.CanCollide = false;
task.wait();
part:SetNetworkOwner(client);
script.Parent.Remote:FireClient(client, cf, couldcollide);
task.wait(5);
print(part:GetNetworkOwner());
-- Script with RunContext set to Client, there's also a remote inside the parent part
script.Parent:WaitForChild("Remote").OnClientEvent:Connect(function(cf, couldcollide)
script.Parent.Anchored = true;
script.Parent.CFrame = cf;
script.Parent.CanCollide = couldcollide;
end)