Help with SetNetworkOwner

So I need to set the network owner to the player when the ball hits the glass. I tried to use a script that unanchors everything and sets the network owner, but now it’s delayed.

image

Local Script:

script.Parent.SetNetworkOwner:FireServer()

Script:

local model = script.Parent
local Parts = model:WaitForChild("Parts")

local function setNetworkOwner(owner)
	for i,v in ipairs(Parts:GetDescendants()) do
		if v:IsA("BasePart") and v.Anchored == false then
			v:SetNetworkOwner(owner)
		end
	end
end

local function unanchorAll()
	for i,v in ipairs(Parts:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false
		end
	end
end

local function anchorAll()
	for i,v in ipairs(Parts:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = true
		end
	end
end

script.SetNetworkOwner.OnServerEvent:Connect(function(player)
	unanchorAll()
	setNetworkOwner(player)
	anchorAll()
end)


I hit the glass but it delays.

5 Likes

Question, Is this a single player game? If so, I’m confused why your using server sided communication.

1 Like

Yes, this is a single player game. I need to set the ownership so the glass doesn’t lag.

1 Like

Then why dont you solely use client sided communication? Makes it wayy easier. Dont have to call remotes, and the lag should be eliminated.

1 Like


The glass freezes in the air.

1 Like

It’s delayed because the code is structed in a very poor preforming way. The delay is from server to client communication. The glass freezing in mid air is because you tell the server to anchor those parts.


Already disabled it

You’ve moved the all the code to the client? I don’t think that should be happening if it is. Is it possible if you can show me the code you have right now(The code that you moved to the client)?

Handle glass destruction completely on client, only use server for points and stuff.

Have you tried to switch up the order?
Set Owner and then unanchor?

Why not add a slight body velocity to the pieces once it’s hit so they scatters as soon as it gets hit

Well, you are not allowed to set the owner on anchored parts.

1 Like

Like have all the parts unanchored and add a bodyvelocity to each part?

I decided to use raycasting.

2 Likes

How do you make it break like that?

1 Like

I just make a triangle in Blender and add Cell Fracture by pressing F3 and change some stuff and it will make the pieces.

1 Like

yeah, but you should use debris service to get rid of the velocity. Maybe it’ll help

There’s no velocity, its anchored. Also, the gravity is set to 0.

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