Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my set network ownership not working?

for i,v in pairs(script.Parent.Parent:GetChildren()) do 

v:SetNetworkOwnershipAuto()
end
local VehicleSeat = script.Parent
wait(1)
VehicleSeat.Changed:Connect(function(Property)
	if Property == "Occupant" then
		local humanoid = VehicleSeat.Occupant
		if humanoid then
			print(humanoid.Parent)
	       local player=game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
			if player then
				print(player)
				for i,v in pairs(script.Parent.Parent:GetChildren()) do 
				
				
				v:SetNetworkOwner(player) 
			end end
			else
			for i,v in pairs(script.Parent.Parent:GetChildren()) do 
			
			v:SetNetworkOwnershipAuto()
		end end 
	end
end)

everything prints up unti lthe line print(humanoid.Parent)

It is a script that is in a car vehicle seat and to prevent lag someone has told me to set ownership and so to test out if the script works, i decided to plant some print commands to see if conditions meet but apparently it gets stuck in the line that says if player then

much help appreciated ,MSDLF

1 comment

0

Is this the entirety of the script? if so it'll run once. You should only set network ownership when the occupant changes.

2 answers

print(humanoid.Parent)

There is no parent of humanoid(your variable), because humanoid is just the value of seat.Occupant, and that's not the way to do that. VehicleSeat.Occupant will be Humanoid, but you need to find where is that humanoid. That humanoid must be inside any player's character, and that print command is also not enough to detect where it is. You just need to detect who sat down to the seat, but I don't know how can you do that.

Hope that helps!

Line 9 is your issue:

local humanoid = VehicleSeat.Occupant

Occupant reads a Humanoid, although what that Humanoid's Parent is is a Character. If you refer to the Wiki, Character is a property, not an object. This means that humanoid.Parent prints nothing because the game can't display a property. So in order to make this work, you would have to do something like this:

local plr = game.Players:GetPlayerFromCharacter(VehicleSeat)
if plr then
	local humanoid = plr.Character.Humanoid -- By the way, Character is a property, which means you can't use methods on it
	if humanoid ~= nil then
		-- Rest of your code
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.