I don’t understand why
Workspace.B_U_S.BusHandler:57: attempt to index nil with ‘SetNetworkOwnershipAuto’
and
Workspace.B_U_S.BusHandler:48: attempt to index nil with ‘SetNetworkOwner’
is nil please help
script:
local bus = script.Parent
local seat = bus.Bus.VehicleSeat
local body = bus.Bus.BusBody.TouchPart
local physicsService = game:GetService(“PhysicsService”)
local defaultCollisionGroup = “Default”
local characterCollisionGroup = “Character”
local cooldown = 0
local occupiedPlayer = nil
local function Cooldown(duration)
local cooldownTag = tick()
cooldown = cooldownTag
delay(duration, function()
if (cooldown == cooldownTag) then
cooldown = 0
end
end)
end
local function setCharacterCollide(character, shouldCollide)
local group = (shouldCollide and defaultCollisionGroup or characterCollisionGroup)
for _,part in ipairs(character:GetDescendants()) do
if (part:IsA(“BasePart”)) then
part.Massless = not shouldCollide
physicsService:SetPartCollisionGroup(part, group)
end
end
end
local function BodyTouched(part)
if (seat.Occupant or cooldown ~= 0) then return end
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if (not player) then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if (not humanoid) then return end
seat:Sit(humanoid)
occupiedPlayer = player
setCharacterCollide(character, false)
bus.PrimaryPart:SetNetworkOwner(player)
Cooldown(4)
end
local function occupantChanged()
if (seat.Occupant) then return end
if (occupiedPlayer.Character) then
setCharacterCollide(occupiedPlayer.Character, true)
end
bus.PrimaryPart:SetNetworkOwnershipAuto()
occupiedPlayer = nil
Cooldown(4)
end
body.Touched:Connect(BodyTouched)
seat:GetPropertyChangedSignal("Occupant"):Connect(occupantChanged)
tutorial: