For some reason, my localscript is randomly working in workspace without setting the model ownership to the player.
I tested a print in the local script without setting the network ownership and it printed.
How can I fix this? I thought local scripts only work if the ownership is set first.
The script is set to client:
NetworkOwner:
local model = script.Parent
local function setNetworkOwner(owner)
for i,v in ipairs(model:GetDescendants()) do
if v:IsA("BasePart") then
local result = v:CanSetNetworkOwnership()
print(result) <-- true
v:SetNetworkOwner(owner)
end
end
end
script.SetNetworkOwner.OnServerEvent:Connect(function(player)
setNetworkOwner(player)
end)
once it is not a script you turned into a local script you will get the results you want
so try adding a local script and not by adding a script and changing it to client
This is intended behaviour, scripts with their RunContext set to client will run for each connected client regardless of their parent. If you don’t want the script to run, disable it or add a LocalScript, not a script with RunContext client.
You don’t have a LocalScript, you have a script with RunContext set to client, they’re two different things. I’m not too sure what you’re asking, do you want the script to run when the parts have their network owner changed?
I see, in that case you could probably just create a remote, then fire the client when the network ownership is set to them. Then on the client in the connected function, do what it is you want to happen. There isn’t any part.NetworkOwnershipGained event so you would need to make a custom implementation.
Yes because on the client you are telling the server to set network ownership of the part to the client, it happens in the correct order. The local script will run for each connected client, regardless of network ownership.