trying to make a hitch script, but it gives me an error saying: 21:30:16.068 - Players.ieatandisbaconhair.PlayerGui.ScreenGui.LocalScript:8: attempt to index field 'Parent' (a nil value)

script:



local plr = game.Players.LocalPlayer
game:GetService("UserInputService").InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.H then
		for i,v in pairs(game.Workspace.Vehicles:GetChildren()) do
			if v.CarOwner then
			local mag = (v.HingePart.Position-v.Trailer.HingePart.Position).Magnitude
			if mag <= 1 then
				local mag2 = (v.HingePart.Position-plr.Character.HumanoidRootPart.Position).Magnitude
				if mag2 <= 10 then
				if v.CarOwner.Value == game.Players.LocalPlayer.Name then
					if v.IsHitched.Value == false then
						v.HitchTrailer:FireServer()
						v.IsHitched.Value = true
					elseif v.IsHitched.Value == true then
						v.UnHitchTrailer:FireServer()
						v.IsHitched.Value = false
					end
				end
				end
			end
			end
		end
	end
end)

2 comments

0

can you tell me what line this error is on?

0

line 8